-3

I have an array like let a = [[[1,2], [3,[1,2,3]]], [2,3]] and want to access the elements using a method/way to return the values like : 12312323 or [1,2,3,1,2,3,2,3]

how can I approach the solution in javascript/nodeJS? thanks

Shahin Ghasemi
  • 1,600
  • 1
  • 20
  • 38
  • [`Array.flat()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Objets_globaux/Array/flat) – Blackhole Jan 20 '19 at 14:00
  • [Try this link instead.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat). Note, not available for Edge. – Andy Jan 20 '19 at 14:03

1 Answers1

-1

You can use Array.flat()

let a = [[[1,2], [3,[1,2,3]]], [2,3]]

let op = a.flat(Infinity)

console.log(op)

You can check browser compatibility here compatibility

Code Maniac
  • 37,143
  • 5
  • 39
  • 60