New custom Array methods.
I'm going to continue with some useful methods for the Array object. The first one makes a copy of the array, not a reference of it.
Array.prototype.Copy=function(){
return this.slice(0)
}
Usage:
array0 = [1, 2, 3, 4];
array1 = [array0, 2, 3, 4];
array2 = array1.Copy();
The second one checks if two arrays are identical, so they have the same elements.
Array.prototype.IdenticalArray = function (Array2) {
for(var i=0;i < this.length;i++){
if(this[i] !== Array2[i]){
return false;
}
}
return true;
}
Usage:
array1 = [1, 2, 3, 4];
array2 = ["1", 2, 3, 4];
if (array1.IdenticalArray(array2)) {
trace("The arrays are identical");
} else{
trace("The arrays are NOT identical");
}
I'm going to continue with some useful methods for the Array object. The first one makes a copy of the array, not a reference of it.
Array.prototype.Copy=function(){
return this.slice(0)
}
Usage:
array0 = [1, 2, 3, 4];
array1 = [array0, 2, 3, 4];
array2 = array1.Copy();
The second one checks if two arrays are identical, so they have the same elements.
Array.prototype.IdenticalArray = function (Array2) {
for(var i=0;i < this.length;i++){
if(this[i] !== Array2[i]){
return false;
}
}
return true;
}
Usage:
array1 = [1, 2, 3, 4];
array2 = ["1", 2, 3, 4];
if (array1.IdenticalArray(array2)) {
trace("The arrays are identical");
} else{
trace("The arrays are NOT identical");
}