假设我有一个数组数组,如下所示:
var arrs = [
[1, "foo", "bar", "baz"],
[2, "bar", "baz", "qux"],
[3, "baz", "qux", "thud"]
];
我想使用 ES6 的解构赋值将每个数组的第一个元素作为一个单独的变量,并将其余元素重新打包为另一个数组。在伪代码中:
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
}
这样的事情可能吗?
最佳答案
这就是 ...
所做的:
for (let [first, ... rest] of arrs) {
关于javascript - 有没有办法重组解构任务的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31102493/