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

HTMLJavascriptProgramming Scripts

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

  • target − The position of the index from where the elements is to be copied.
  • begin − The index to start copying the element. This is an optional parameter.
  • end − The index to end copying the element. This is an optional parameter.

Example

You can try to run the following code to learn how to work with 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>
raja
Published on 26-Feb-2018 12:31:51
Advertisements