What does the following code output? const arr = [1, [2, [3]]]; console.log(arr.flat(1));

JavaScript Developer Medium

JavaScript Developer — Medium

What does the following code output? const arr = [1, [2, [3]]]; console.log(arr.flat(1));

Key points

  • The flat() method flattens arrays by a specified depth
  • In this case, the depth is set to 1
  • Only the first level of nested arrays is flattened
  • The output removes one level of nesting

Ready to go further?

Related questions