0

I run into the following problem, the following array: [[1,2,3],[4,5,6],[7,8,9]] I must go through it and get the following result [1, 2,3,4,5,6,7,8,9]. Currently I get the same result. Here my code:

 let main= [[1,2,3],[4,5,6],[7,8,9]]

 let result= [].concat(
   main.map((e)=>{
     return e
   })
 )

 console.log(result)
Usiel
  • 671
  • 3
  • 14
  • 2
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat – James Jun 01 '22 at 17:34
  • 1
    `map(e => e)` (equivalent to your code) basically just produces a copy of the original array. You want `reduce`, or better yet, `flat`. – Heretic Monkey Jun 01 '22 at 17:35
  • 1
    @HereticMonkey if `concat` is to be used, then `[].concat(...main)` can also work. – VLAZ Jun 01 '22 at 17:37

0 Answers0