How to use the Array.from() Method In Javascript
Using the Array.from() method is another way to clone an array in JavaScript. This method creates a new array from an existing array, using an optional mapping function to transform the values in the new array.
Example: This example shows the implementation of the above-explained approach.
const originalArray = [1, 2, 3];
const clonedArray = Array.from(originalArray);
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.