Why the deconstruction of the array this behavior?

const a1 = [ 1, 5, 8, 7], a2 = [];
[a2[0], a2[2], a2[3], a2[1]] = a1;
console.log(a2); // [1, 7, 5, 8]
June 3rd 19 at 19:24
1 answer
June 3rd 19 at 19:26
Solution
What is not clear?
Without the deconstruction will look like this:
const a1 = [ 1, 5, 8, 7], a2 = [];

a2[0] = a1[0];
a2[2] = a1[1];
a2[3] = a1[2];
a2[1] = a1[3];

console.log(a2); // [1, 7, 5, 8]

Find more questions by tags JavaScript