Is there a way to restructure the destructuring destination part?
Let's say I have an array of arrays, for example:
var arrs = [
[1, "foo", "bar", "baz"],
[2, "bar", "baz", "qux"],
[3, "baz", "qux", "thud"]
];
I want to use ES6's destructuring assignment to get the first element of each array as a separate variable and repackage the rest of the elements as a different array. In pseudocode:
for (let [first, *rest] of arrs) { // What is the proper way to do *rest?
console.log(first); // Should be a number
console.log(rest); // Should be an array of strings
}
Is this possible?
+3
source to share