Mick
0
Q:

unpack array into variables javascript

var yourArr = [1, 2, 3]

[one, , three] = yourArray // 2 is ignored
// one == 1 && three == 3
0
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"
0

New to Communities?

Join the community