Search code examples
javascriptarraysreduceflat

Flatten array to 1 line


Hey I need some help here in javascript

[ [ 0, 0, 0, -8.5, 28, 8.5 ],
  [ 1, 1, -3, 0, 3, 12 ],
  [ 2, 2, -0.5, 0, 0.5, 5.333333333333333 ] ]

I want that array above to be in the form of this

 0 0 0 -8.5 28 8.5, 1 1 -3 0 3 12, 2 2 -0.5 0 0.5 5.333333333333333

concat and reduce is placing a comma after each value


Solution

  • arr.map(item => item.join(' ')).join(',');