var a = [1, 2, 3];
var b = a.slice(0);
b[1] = 20;
alert(a[1]); //->2
alert(b[1]); //->20
If the two values are different, it means the cloning is successful. Of course, you can also use the Array prototype:
Array.prototype.clone = function () {
return this.slice(0);
}
var a = [1, 2, 3 ];
var b = a.clone();
b[1] = 20;
alert(a[1]); //->2
alert(b[1]) ; //->20