jadjoubran / codetogo.io

🚀 JavaScript code to go - Find updated snippets for common JavaScript use cases
https://codetogo.io
MIT License
233 stars 30 forks source link

Use Case Suggestion: copywithin() #335

Open adampicard opened 11 months ago

adampicard commented 11 months ago

How to copy part of an array to another location in the same array and returns the modified array without changing its length.

let fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
fruits.copyWithin(3, 0, 2);
console.log(fruits); // Output: ['apple', 'banana', 'cherry', 'apple', 'banana']