Javascript Array where(func)

Description

Javascript Array where(func)

Array.prototype.where = function(func) {
  var result = [];
  for (var i = 0; i < this.length; i++)
    if (func(this[i]))
      result.push(this[i]);// w w w  .j a v  a 2s  .  c  om
  return result;
};

Javascript Array Where(func)

Array.prototype.Where = function (func) {
    var result = [];
    this.forEach(function (item) {
        if (func(item)) {
            result.push( item );//from  w ww.j av  a2 s  .  c  om
        }
    });
    return result;
};

Javascript Array where(func)

Array.prototype.where = function(func){
 var result = [];
 forEach(this, function (element) {
  if(func(element)){
   result.push(element);/*from ww  w. ja va 2  s .co m*/
  }
 });
 return result;
}



PreviousNext

Related