const a=[1,2,3,4,5];
const [n]=a;
console.log(n);
I need to know how does something inside square brackets after const means, and why it stored only 1 and not the entire array.
>Solution :
It is ES6 Destructuring Assignment.
const a = [1,2,3,4,5];
const [n] = a;
const [m, o] = a;
const [p, q, r] = a;
const [...s] = a;
const [t, u] = a;
console.log(n); // 1
console.log(m, o); // 1 2
console.log(p, q, r); // 1 2 3
console.log(...s); // 1 2 3 4 5
console.log([...s]); // [1, 2, 3, 4, 5]
console.log(u); // 2