QP School
JavaScript Array copyWithin() example - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: JavaScript Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=6)
+--- Thread: JavaScript Array copyWithin() example (/showthread.php?tid=4089)



JavaScript Array copyWithin() example - Qomplainerz - 04-04-2023

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;