flat an array - Node.js Array

Node.js examples for Array:Flatten

Description

flat an array

Demo Code


var flattenArrays = [[1, 2, 3], [4, 5], [6]];

function flatten(array) {
  return array.reduce(function(a,b) {
    console.log(a,b);/*from ww  w.j  av a2  s . co  m*/
    return a.concat(b);
  })
}

console.log(flatten(flattenArrays))

Related Tutorials