Javascript Array myEach(cb)

Description

Javascript Array myEach(cb)


Array.prototype.myEach = function (cb) {
  for (var i = 0; i < this.length; i++) {
    cb(this[i]);/*from   w w w .  jav  a  2 s.  com*/
  }

  return this;
};

Javascript Array myEach(cb)

Array.prototype.myEach = function (cb) {

  for (let i = 0; i < this.length; i++){
    cb(this[i]);/* w  w w  .j  a v a  2  s . c  o m*/
  }
};

let myEachArray = [1,2,3];

// myEachArray.myEach((el) => { console.log(el * 2); });



PreviousNext

Related