Nodejs Array Merge All mergeAll()

Here you can find the source of mergeAll()

Method Source Code

var school = [//from   w w  w. jav  a  2 s .  c  o  m
   [1, 2, 3],
   [4, 5, 6, 7, 8, 3],
   [5, 3, 5]
];

Array.prototype.mergeAll = function() {
   var result = [];
   this.forEach(function(subArray) {
      result.push.apply(result, subArray);
   });
   return result;
};

var a = school.mergeAll(function(x) {
   return x;
});

console.log(a);

Related

  1. mergeAll()
    Array.prototype.mergeAll = function() {
      var results = [];
      this.forEach(function(subArray) {
        subArray.forEach(function(number) {
          results.push(number);
        });
      });
      return results;
    };
    ...
    
  2. mergeAll()
    Array.prototype.mergeAll = function() {
        var results = [];
        this.forEach(function(subArray) {
        subArray.forEach(function(element) {
          results.push(element);
        });
        });
        return results;
    };
    ...
    
  3. mergeAll()
    Array.prototype.mergeAll = function() {
        var results = [];
        this.forEach(function(subArray) {
          subArray.forEach(function(itemInArray) {
            results.push(itemInArray);
          });
        });
        return results;
    };
    ...
    
  4. mergeAll()
    Array.prototype.mergeAll = function(){
      var result = [];
      this.forEach(function(subArray){
        subArray.forEach(function(item){
          result.push(item);
        })
      })
      return result;