how to transform an array of arrays into a single array in javascript? [duplicate]

-2

Given the array: [[1,2,3], [4,5,6]]

How to transformer in: [1,2,3,4,5,6]

    
asked by anonymous 26.07.2018 / 21:09

2 answers

2
var x = [["1", "2", "3"], ["3", "4", "5"]];    
var y = x[0].concat(x[1]);
    
26.07.2018 / 21:23
2

You can do this as follows:

var matriz = [
  ['A', 'B', 'C'],
  ['D'],
  ['E', 'F'],
  ['G', 'H', 'I', 'J']
]

var array = matriz.reduce((list, sub) => list.concat(sub), [])
console.log(array)
    
26.07.2018 / 21:27