Nodejs Array Concatenate concatAll()

Here you can find the source of concatAll()

Method Source Code

//Let's add a concatAll() function to the Array type. The concatAll() function iterates over each 
//sub-array in the array and collects the results in a new, flat array. Notice that the concatAll() 
//function expects each item in the array to be another array.
//concatAll is a very simple function, so much so that it may not be obvious yet how it can be combined with map() to query a tree.

Array.prototype.concatAll = function() {
   var results = [];
   this.forEach(function(subArray) {
      results.push.apply(results, subArray);
   });//ww w.j  ava  2  s. c om

   return results;
};

// JSON.stringify([ [1,2,3], [4,5,6], [7,8,9] ].concatAll()) === "[1,2,3,4,5,6,7,8,9]"
// [1,2,3].concatAll(); // throws an error because this is a one-dimensional array

Related

  1. concatAll()
    var exchanges = [
        [
            {symbol: "XFZ", price: 340.22, volume: 202373},
            {symbol: "ABC", price: 521.19, volume: 737323}
        ],
        [
             {symbol: "DEF", price: 987.82, volume: 2373},
             {symbol: "HIJ", price: 200.82, volume: 373}
        ]
    ...
    
  2. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        results.push.apply(results, subArray);
      });
      return results;
    };
    
  3. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach( subArray => {
        subArray.forEach(elt => results.push(elt));
      });
      return results;
    };
    
  4. concatAll()
    const exchanges= [
      [
        {symbol: 'XFX', price: 240.22, volume: 23432},
        {symbol: 'TNZ', price: 332.19, volume: 234},
      ],
      [
        {symbol: 'JXJ', price: 120.22, volume: 5323},
        {symbol: 'NYN', price: 88.47, volume: 98275},
      ],
    ...
    
  5. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach(function(item) {
          results.push(item);
        });
      });
      return results;
    };
    ...
    
  6. concatAll()
    Array.prototype.concatAll = function() {
        this.forEach( function(val1) {
            val1.forEach( function (val2) {
                    return allWords.push(val2);
            });
        });
    };
    
  7. concatAll()
    var exchanges = [
      [
          { symbol: "XFX", price: 240.22, volume: 23432 },
          { symbol: "TNZ", price: 332.19, volume: 234 }
        ],
      [
          { symbol: "JXJ", price: 120.22, volume: 5323 },
          { symbol: "NYN", price: 88.47, volume: 98275 }
        ]
    ...
    
  8. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach(function(item) {
          results.push(item);
        });
      });
      return result;