Javascript Array filter(iteratee, thisArg)

Description

Javascript Array filter(iteratee, thisArg)


Array.prototype.filter = function(iteratee, thisArg) {
 if (typeof iteratee !== "function") {
  throw new TypeError(iteratee + ' is not a function')
 }
 let arr = [];//from ww w.j av  a 2 s  .co m
 for (let i = 0, len = this.length; i < len; i++) {
  if (iteratee.call(thisArg, this[i], i, this) === true) {
   arr.push(this[i]);
  }
 }
 return arr;
}



PreviousNext

Related