Which of the following is the correct syntax for destructuring an array in JavaScript?

  • let [x, y] = [1, 2];
  • let {x, y} = [1, 2];
  • let (x, y) = [1, 2];
  • let x = [1, 2];
Destructuring an array in JavaScript is done using square brackets []. The correct syntax is let [x, y] = [1, 2];. The other options are either for object destructuring or use incorrect syntax.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *