Nodejs Array Map map(callback, thisArg)

Here you can find the source of map(callback, thisArg)

Method Source Code

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');
   }/*w w  w. j a  va  2 s  .  c om*/
   for(var i = 0, len = this.length; i < len; i++){
      newArr[i] = callback.call(thisArg, this[i], i , this);
   };
   return newArr;
};
function fn(value, i , obj){
   return value*2;
}
var newarr = [1,2,3,4].map(fn);

Related

  1. map(callback)
    Array.prototype.map = function(callback){
        const newArr = []
        for(let i = 0; i < this.length; i += 1){
            let newValue = callback(this[i])
            newArr.push(newValue)
        return newArr
    var someArray = [1,2,3,4]
    ...
    
  2. map(callback)
    Array.prototype.map = function(callback) {
      for(var i = 0, l = this.length; i < l; i++) {
        this[i] = callback(i, this[i]);
      return this;
    
  3. map(callback)
    Array.prototype.map = function (callback) {
      var mapped = [];
      function mutation(el) {
        mapped.push(callback(el));
      this.each(mutation);
      return mapped;
    };
    
  4. 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 = [];
    ...
    
  5. map(callback)
    Array.prototype.map = function(callback) {
      var returnArray=[];
      for (var i=0; i<this.length; i++) {
        returnArray.push(callback(this[i]));
      return returnArray;
    };
    
  6. 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;
    ...
    
  7. 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;
    
  8. map(cb)
    Array.prototype.map = function(cb){
        var arr = Object(this);
        var res = []
        for(var i=0;i<arr.length;i++){
            res[i] = cb.call(arr[i], i);
        return res;
    
  9. map(command)
    Array.prototype.map = function(command){
      var outArray = [];
      this.each(function(x){
        outArray.push(command(x));
      });
      return outArray;
    };