Articles → JAVASCRIPT → Clone An Array Using The Spread Operator In Javascript

Clone An Array Using The Spread Operator In Javascript






Example




<script>
  numbers = [1, 2, 3];
  clonnedNumbersArray = [...numbers]; // cloning an array using the spread operator
  document.write("Length of the clonned array:" + clonnedNumbersArray.length);               
</script>

Output


Picture showing the output of clonning an array using the spread operator in Javascript



Posted By  -  Karan Gupta
 
Posted On  -  Monday, August 23, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250