Nodejs Array Concatenate concatAll()

Here you can find the source of concatAll()

Method Source Code

let data = [//w  w w.jav a 2s.c om
    [
        {name: "IBM", price:12},
        {name: "Apple", price:120}        
    ],
    [
        {name: "Google", price:100},
        {name: "MorganStanley", price:30}        
    ]
]
Array.prototype.concatAll = function () {
    let results = [];
    
    this.forEach(function(item){
        item.forEach(function(subItem){
            results.push(subItem);
        })
    })
    return results;
}
data.concatAll().forEach(function(item){
    console.log("==== concatAll: " + JSON.stringify(item));
})

Related

  1. concatAll()
    Array.prototype.concatAll = function() {
      let results = [];
        for (let i = 0; i < this.length; i++) {
            results.push.apply(results, this[i]);
      return results;
    };
    
  2. concatAll()
    Array.prototype.concatAll = function() {
      return this.reduce((results, current) => {
        if(Array.isArray(current)) {
            return results.concat(current).concatAll();
        } else {
            return (results.push(current), results);
      }, []);
    };
    ...
    
  3. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        if (Array.isArray(subArray)) {
          subArray.forEach(function(item) {
            results.push(item);
          });
      });
    ...
    
  4. concatAll()
    Array.prototype.concatAll = function () {
      let results = [];
      this.forEach(function (subArray) {
        results.push.apply(results, subArray);
      });
      return results;
    };
    
  5. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach((i) => {
          results.push(i);
        });
      });
      return results;
    };
    ...
    
  6. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach(function(item){
          results.push(item)
        })
      });
      return results;
    };
    ...
    
  7. concatAll()
    Array.prototype.concatAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach(function(element){
          results.push(element);
        });
      });
      return results;
    };
    ...
    
  8. concatAll()
    let 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 },
      ],
    ...
    
  9. 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}
        ]
    ...