Javascript Array mapp(callback)

Description

Javascript Array mapp(callback)


// Nov 21/*from   w ww .j  ava 2s  . c o m*/
// Creating Map 


Array.prototype.mapp = function(callback) {
  var newArray = [];
  for(var i = 0; i < this.length; i++){
    newArray.push(callback(this[i]));
  }
  return newArray;
}

var x = [1,2,3];

x.mapp(function(ele) {
  return ele * 3;
}) // [3, 6, 9]



PreviousNext

Related