Today, custom Array methods.
First one counts how many times a value exist in an Array:
Array.prototype.Count=function(value) {
var cont;
for(var i=0;i < this.length;++i){
if(this[i] == value){
++cont;
}
}
return cont;
}
Usage:
myArray = new Array("apple","pear","apple","orange");
countApples = myArray.Count("apple")
countApples = 2
First one counts how many times a value exist in an Array:
Array.prototype.Count=function(value) {
var cont;
for(var i=0;i < this.length;++i){
if(this[i] == value){
++cont;
}
}
return cont;
}
Usage:
myArray = new Array("apple","pear","apple","orange");
countApples = myArray.Count("apple")
countApples = 2