0

How do multiple arrays in a single array merge an array?

how to end up with this

[1,2,3,4,5,6]

These codes

[  
  [
    1,
    2
  ],
  [
    3,
    4
  ],
  [
    5,
    6
  ]
]

wen tian
  • 433
  • 2
  • 5
  • 18
  • 1
    You can use `.flat()` if using mordern browsers – Nick Parsons Aug 05 '19 at 04:23
  • If you want to write a function which converts an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4]. ```function flatten(elements) { return elements.reduce((result, current) => { return result.concat(Array.isArray(current) ? flatten(current) : current); }, []); };``` Upvote this comment if this helped your work. –  Aug 05 '19 at 04:27

0 Answers0