How to create a new array from the existing one in JavaScript ?

If you want to create a new array from the existing array in JavaScript, you can use the Array’s map function as shown in the below code snippet.

How to create a new array from the existing one in JavaScript ?

var oldArray = new Array(1, 3, 4, 5, 6, 3);
var newArray = oldArray.map(function(item) {
    return item;
});
console.log(newArray);

Leave a Reply