JavaScript quick tips: Array.copyWithin()
Rajika Imal
Posted on October 31, 2020
Array.prototype.copyWithin()
does a copy (shallow) of the selected elements within the same array, to a specified index.
To copy value in index 3 to index 1
const myArray = [1, 2, 3, 4, 5];
myArray.copyWithin(1, 3, 4); // [1, 4, 3, 4, 5]
To copy all values from specified index to the end to a given index
const myArray = [1, 2, 3, 4, 5];
myArray.copyWithin(1, 3); // [1, 4, 5, 4, 5]
💖 💪 🙅 🚩
Rajika Imal
Posted on October 31, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.