Categories
JavaScript Answers

How to unpack array into separate variables in JavaScript?

Spread the love

To unpack array into separate variables in JavaScript, we use destructuring.

For instance, we write

const arr = ["one", "two"];
const [one, two] = arr;

to assign the entries in arr into their own variables with the destructuring syntax.

So one is 'one' and two is 'two'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.