Tag Archives: David Walsh

Javascript – Clone an Array

Here is a simple way to copy an array, which contains primitive data types like string and integer, by value in Javascript.

var myArray = ['eureka', 30, true];
var clone = myArray.slice(0);

myArray[1] = 100;
console.log(myArray[1]); // output: 100
console.log(clone[1]);   // output: 30

Continue reading Javascript – Clone an Array