The copyWithin() method copies a part of the array to the same array and returns it without modifying its size, i.e. copies the array elements of the array in the same array. Let's take a look at the specific usage of the copyWithin method.
Let’s first take a look at the basic syntax of copyWithin()
array.copyWithin(target,start,end)
target: The index position of the element to be copied (required) .
start: This is optional. The index position is the element to start copying (default is 0).
end: This is optional. The index position at which to stop copying the element (defaults to array.length).
Let’s look at the specific example of copyWithin()
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> var array = [ 1, 2, 3, 4, 5, 6, 7 ]; console.log(array.copyWithin(0, 3, 6)); </script> </body> </html>
The running result is as follows
Array [4, 5, 6, 4, 5, 6, 7]
This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use copyWithin method. For more information, please follow other related articles on the PHP Chinese website!