This tutorial shows you four popular ways:
- Spread Operator
- Array.slice method
- Array.concat method
Since ES6 has released, this has been the most popular and easiest method to duplicate an array.
Use spread operator to create a clone of your array by “spreading” the item of the original array into a clone:
The second approach is using slice() method.
Just calling .slice() on the original array to clone the array.
You could also use .concat() method for cloning an array. Array.concat combines array with values or other arrays.
There is another (but not the last one indeed) method that could simply duplicate a given array.