Open adampicard opened 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']
3 is the target index where the copying begins.
0 is the start index from where to start copying elements (inclusive).
2 is the end index where to end copying elements (not inclusive).
The elements 'apple' and 'banana' will be copied to indices 3 and 4.
The original elements at indices 3 and 4 ('date' and 'elderberry') will be overwritten.
How to copy part of an array to another location in the same array and returns the modified array without changing its length.
3 is the target index where the copying begins.
0 is the start index from where to start copying elements (inclusive).
2 is the end index where to end copying elements (not inclusive).
The elements 'apple' and 'banana' will be copied to indices 3 and 4.
The original elements at indices 3 and 4 ('date' and 'elderberry') will be overwritten.