Javascript Array numberOfOccurrences(element)

Description

Javascript Array numberOfOccurrences(element)


Array.prototype.numberOfOccurrences = function (element) {
    //from  w ww .  j a  va2  s .  co m
    var counter = 0;
    var self = this;
    for(var i = 0; i < self.length; i++)
    {
        if(self[i] == element){ 
         counter++; 
     }
    }
    
    return counter;
    
}



PreviousNext

Related