Nodejs Array Map map(cb)

Here you can find the source of map(cb)

Method Source Code

//Implement map function for Array
Array.prototype.map = function(cb){
    var arr = Object(this);
    var res = []/* ww  w . j av a2  s. c  o m*/
    for(var i=0;i<arr.length;i++){
        res[i] = cb.call(arr[i], i);
    }
    return res;
}

Related

  1. map(callback)
    Array.prototype.map = function(callback) {
      var result = [];
      this.forEach(function(item) {
        result.push(callback(item));
      });
      return result;
    };
    Array.prototype.concatAll = function(array) {
      var results = [];
    ...
    
  2. map(callback)
    Array.prototype.map = function(callback) {
      var returnArray=[];
      for (var i=0; i<this.length; i++) {
        returnArray.push(callback(this[i]));
      return returnArray;
    };
    
  3. map(callback, thisArg)
    Array.prototype.map = function(callback, thisArg){
      var newArr = [];
      if(callback && Object.prototype.toString.call(callback) != "[object Function]"){
        throw new TypeError('callback is not a function');
      for(var i = 0, len = this.length; i < len; i++){
        newArr[i] = callback.call(thisArg, this[i], i , this);
      };
      return newArr;
    ...
    
  4. map(callback, thisArg)
    Array.prototype.map = Array.prototype.map || (function(callback, thisArg) {
      var T, A, k;
      var O = Object(this);
      var len = O.length >>> 0;
      if (arguments.length > 1) T = thisArg;
      A = new Array(len);
      k = 0;
      while (k < len) {
        var kValue, mappedValue;
    ...
    
  5. map(callbackfn, thisArg)
    Array.prototype.map = function (callbackfn, thisArg) {
      var res = [];
      for (var i=0; i<this.length; i++)
        res[i] = Kernel.Reflect.apply(callbackfn, thisArg, [this[i], i, this]);
      return res;
    
  6. map(command)
    Array.prototype.map = function(command){
      var outArray = [];
      this.each(function(x){
        outArray.push(command(x));
      });
      return outArray;
    };
    
  7. map(f)
    Array.prototype.map = function(f){
      var newArray = [];
      var i;
      for( i = 0; i<this.length; i++){
        newArray.push(f(this[i],i,this));
      return newArray;
    
  8. map(f)
    var arr = [0,1,2,3,4];
    var triple = function(x) { return x * 3; };
    Array.prototype.map = function(f) {
        var newArr = [];
        for (var i = 0; i < this.length; i++) {
            newArr.push(f(this[i]));
        return newArr;
    };
    ...
    
  9. map(f)
    Array.prototype.map = function(f) {
        var i;
        var mapped = [];
        for (i = 0; i < this.length; i++) {
      mapped.push(f(this[i]));
        return mapped;
    };