How to use the Array.slice() Method In Javascript
We use the slice method to create a shallow copy of an array. This method creates a new array with a subset of the elements from the original array.
Example: This example shows the implementation of the above-explained approach.
const originalArray = [1, 2, 3];
const clonedArray = originalArray.slice();
console.log(clonedArray);
Output
[ 1, 2, 3 ]
How to clone an array in JavaScript ?
In JavaScript, cloning an array means creating a new array with the same elements as the original array. Cloning an array in JavaScript is useful when you want to create a new array that has the same elements as an existing array, without modifying the original array.