I am looking to create a duplicate of a multidimensional array in order to experiment with the cloned array without impacting the original array.
Here is the function I am currently using for this purpose:
Array.prototype.clone = function () {
var newArray = new Array(this.length);
for(var i=0; i < this.length; i++ ){
newArray[i] = this[i];
}
return newArray;
};
The issue with this approach is that it clones all arrays due to its usage of the array prototype. Can anyone suggest a better way to achieve this?