Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JavaScript Array copyWithin() example
#1
Code:
const fruits1 =
      [
        "Banana",
        "Orange",
        "Apple",
        "Mango"
      ];

const fruits2 =
      [
        "Banana",
        "Orange",
        "Apple",
        "Mango"
      ];

// Copy the first two elements to the last two elements

let text = fruits1.copyWithin(2, 0);

document.getElementById("output1").innerHTML = text;

// Copy the last two elements to the first two elements

let text2 = fruits2.copyWithin(0, 2);

document.getElementById("output2").innerHTML = text2;
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JavaScript - Array find() example (returns the value) Qomplainerz 0 409 04-04-2023, 08:12 AM
Last Post: Qomplainerz
  JavaScript Array findIndex() examples (returns the index) Qomplainerz 0 362 04-04-2023, 08:10 AM
Last Post: Qomplainerz
  JavaScript exercises and solutions - Iterating through an array with keys and values Qomplainerz 0 317 04-04-2023, 07:52 AM
Last Post: Qomplainerz
  JavaScript - Get the length of an array Qomplainerz 0 307 04-04-2023, 07:45 AM
Last Post: Qomplainerz
  JavaScript array constructor Qomplainerz 0 309 04-04-2023, 07:43 AM
Last Post: Qomplainerz
  JavaScript Array entries() example Qomplainerz 0 318 04-04-2023, 07:42 AM
Last Post: Qomplainerz
  JavaScript Array every() example Qomplainerz 0 310 04-04-2023, 07:42 AM
Last Post: Qomplainerz
  JavaScript Array fill() method examples Qomplainerz 0 310 04-04-2023, 07:41 AM
Last Post: Qomplainerz
  Clone an array in JavaScript Qomplainerz 0 295 04-04-2023, 07:38 AM
Last Post: Qomplainerz
  Add elements at the beginning of an array in JavaScript Qomplainerz 0 265 04-04-2023, 07:37 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 4 Guest(s)