Home  >  Article  >  Web Front-end  >  What is the usage of copyWithin() method in JavaScript?

What is the usage of copyWithin() method in JavaScript?

WBOY
WBOYforward
2023-09-02 16:57:031424browse

What is the usage of copyWithin() method in JavaScript?

Use the copyWithin() method in JavaScript to copy array elements. You can set the index from where (index) the element is copied. The following are the elements supported by JavaScript.

  • target − The index position of the element to be copied.
  • begin − The index at which to start copying the element. This is an optional parameter.
  • end − Index of the end copied element. This is an optional parameter.

Example

You can try running the following code to learn how to use the copyWithin() method in JavaScript.

<!DOCTYPE html>
<html>
   <body>
      <script>
         var num = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"];
         document.write(num);

         document.write("<br>"+num.copyWithin(3,0,4));
      </script>
   </body>
</html>

The above is the detailed content of What is the usage of copyWithin() method in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete