Nodejs Array Map map(projectionFunction)

Here you can find the source of map(projectionFunction)

Method Source Code

Array.prototype.map = function(projectionFunction) {
  var reuslts = [];
  this.forEach(function(itemInArray){
    results.push(projectionFunction(itemInArray));
  })//from  w w  w.j a  va 2 s. co  m
  return results;
}

Related

  1. map(handler)
    Array.prototype.map = function (handler) {
        var result = []
        for (var i = 0; i < this.length; i++) {
            result.push(handler(this[i]))
        return result
    
  2. map(iterator)
    Array.prototype.map = function(iterator) {
      var results = [];
      for (var i = 0, len = this.length; i < len; i++) {
        results.push(iterator(this[i], i));
      return results;
    };
    
  3. map(iterator, context)
    Array.prototype.map = function (iterator, context) {
        baidu.check("function(,.+)?","baidu.array.map");
        var i, n,
            array = baidu.array([]);
        for (i=0, n=this.length; i < n; i++) {
            array[i] = iterator.call(context || this, this[i], i, this);
        return array;
    };
    ...
    
  4. map(mapper)
    Array.prototype.map = function(mapper) {
       var result = [];
       for (var i = 0; i < this.length; ++i) {
          result.push(mapper(this[i]));
       return result;
    };
    
  5. map(mappingRelation)
    Array.prototype.map = function(mappingRelation){
      return this.reduce(function(accumulator, value){
        return accumulator.concat(mappingRelation(value));
      }, []);
    
  6. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(itemInArray+1);
      });
      console.log(results);
      return results;
    };
    
  7. map(projectionFunction)
    Array.prototype.map = function (projectionFunction) {
      var results = [];
      this.forEach(function (itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  8. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    
  9. map(projectionFunction)
    Array.prototype.map = function(projectionFunction) {
      var results = [];
      this.forEach(function(itemInArray) {
        results.push(projectionFunction(itemInArray));
      });
      return results;
    };
    console.log(JSON.stringify([1,2,3].map(function(x) { return x + 1; })))