Nodejs Array Map map(from, to)

Here you can find the source of map(from, to)

Method Source Code

/**//  w  w  w  . ja  v a  2  s  .  c  om
 * Creates an associative array mapping one field to another of an array of objects
 * @param {String} from key of the resulting associative array  
 * @param {String} to value of the resulting associative array
 * @return associative array mapping one field to another of an array of objects
 * @type Array
 * @author  Oliver Schrenk <oliver.schrenk@gmail.com>
 */
Array.prototype.map = function(from, to) {
    var newArray = [];
    for (var i = 0; i < this.length; i++) {
        if (this[i][from] != undefined && this[i][to] != undefined) {
            newArray[this[i][from]] = this[i][to];
        }
    }
    return newArray;
};

Related

  1. map(f)
    Array.prototype.map = Array.prototype.map || function (f) {
      var result = [];
      this.each(function (element) {
        result.push(f(element, result.length));
      });
      return result;
    };
    
  2. map(fn)
    Array.prototype.map = function(fn) {
      let temp = []
      temp.push(fn(this[0], 0, this))
      this.reduce((preValue, value, index, array) => {
        temp.push(fn(value, index, array))
        return value
      })
      return temp
    
  3. map(fn)
    Array.prototype.map = function(fn) 
        var r = [];
        for (var i=0;i<this.length;i++)
            r.push(fn(this[i]));
        return r; 
    
  4. map(fn, context)
    Array.prototype.map = function(fn, context) {
      if (typeof fn != "function") {
        throw new TypeError(fn + " is not a function");
      if (typeof context === 'undefined') {
        context = this;
      var result = new Array(this.length);
      for (var i = 0, l = this.length; i < l; ++i) {
    ...
    
  5. map(fn,thisObj)
    if(!Array.prototype.map) {
    Array.prototype.map = function(fn,thisObj)
      var scope = thisObj || window;
      var a = [];
      for(var i=0, j=this.length; i < j; ++i) {
        a.push(fn.call(scope,this[i],i,this));
      return a;
    ...
    
  6. map(fun /*, thisp*/)
    Array.prototype.map = function(fun ) {
        var len = this.length;
        if (typeof fun != "function")
          throw new TypeError();
        var res = new Array(len);
        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
          if (i in this)
    ...
    
  7. map(fun /*, thisp*/)
    Array.prototype.map = function(fun ) {
        var len = this.length;
        if (typeof fun != "function")
          throw new TypeError();
        var res = new Array(len);
        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
          if (i in this)
    ...
    
  8. map(fun /*, thisp*/)
    Array.prototype.map = Array.prototype.map || function(fun ) {
        var len = this.length >>> 0;
        if (typeof fun != "function") {
            throw new TypeError();
        var res = new Array(len);
        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) {
    ...
    
  9. map(func)
    Array.prototype.map = function(func){
      var result = [];
      forEach(this, function (element) {
        result.push(func(element));
      });
      return result;