Home  >  Article  >  Web Front-end  >  How to use copyWithin method

How to use copyWithin method

不言
不言Original
2019-02-20 15:19:503211browse

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.

How to use 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn