What is the output of the following? “`js const arr = [1, [2, [3, [4]]]]; console.log(arr.flat(Infinity)); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js const arr = [1, [2, [3, [4]]]]; console.log(arr.flat(Infinity)); “`

Key points

  • The `flat()` method removes nested arrays
  • The parameter `Infinity` ensures all levels of nesting are flattened
  • The final output is a single-level array with all elements
  • Remember to use `flat()` with the appropriate parameter

Ready to go further?

Related questions