Let us have a look in below mentioned example Below of the Array.copyWithin() method.
Array 4, 5, 6, 4, 5, 6, 7
The Array.copyWithin() method considers an array first and then copies part of an array to the same array itself and returns it, without modifying its size but yet the modified data whatever user wishes to have in other’s place i.e, copies array element of an array within the same array.
array.copyWithin(target, start, end)
Parameters: This method accepts three parameters as mentioned above and described below:
- target: The index position to copy the elements to(Required).
- start: It is optional. The index position to start copying elements from (default is 0).
- end: It is optional. The index position to stop copying elements from (default is array.length).
Return value: It returns the modified array.
More example codes for the above method are as follows:
Array 5, 6, 7, 4, 5, 6, 7
Array 1, 2, 3, 1, 2, 3, 4
Array 5, 2, 3, 4, 5, 6, 7
- Google Chrome 45.0
- Microsoft Edge 12.0
- Mozilla Firefox 32.0
- Opera 32.0
- Safari 9