Javascript Array filter_by(filters)

Description

Javascript Array filter_by(filters)


Array.prototype.filter_by = function(filters) {
 var new_list = [];
 var match = true;
 for(var i = 0; i < this.length; i++) {
  for(var filter_key in filters) {
   if(this[i][filter_key] != filters[filter_key])
    match = false/*w  w w  .j a v  a 2 s  . c om*/
   if(match) {
    new_list.push(this[i]);
   }
  }
 }
 return new_list;
}



PreviousNext

Related