【发布时间】:2015-06-28 17:10:29
【问题描述】:
假设我有一个数组数组,如下所示:
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
}
这样的事情可能吗?
【问题讨论】:
-
groupBy(x => `${x.type}-{x.status}`
标签: javascript ecmascript-6 destructuring