js array to variables code example

Example 1: unpack list javascript

var yourArray = [1, 2, 3, "four"]
// you can unpack those values by doing:
[a, b, c, d] = yourArray // If you want to unpack in variables

...yourArray // If you want to unpack directly where the "..." is (This One is mostly used to give argument to a function)
//Exemple:
consloe.log(yourArray) // will print: [1, 2, 3, "four"]
consloe.log(...yourArray) // will print: 1 2 3 "four"

Example 2: mdn destructuring

let a, b;

[a, b] = [1, 2];
console.log(a); // 1
console.log(b); // 2