How to use destructuring assignment to set values from array into variables and sub array in JavaScript

1 Answer

0 votes
let a, b
const arr = [7, 9, 8, 1, 4, 5];

[a, b, ...subaray] = arr;

console.log(a);

console.log(b);

console.log(subaray);




/*
run:

7
9
[8, 1, 4, 5]

*/

 



answered Nov 13, 2020 by avibootz
...