1.5 KiB
1.5 KiB
title | localeTitle |
---|---|
Use Destructuring Assignment with the Rest Operator to Reassign Array Elements | 使用与Rest运算符的Destructuring Assignment重新分配数组元素 |
使用与Rest运算符的Destructuring Assignment重新分配数组元素
请记住,rest运算符允许可变数量的参数。在这个挑战中,你必须摆脱数组的前两个元素。
提示1:
将前两个元素分配给两个随机变量。
提示2:
将数组的剩余部分设置为...arr
。
=======
提示1
使用destructuring来创建arr
变量。
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [arr] = list; // change this
// change code above this line
return arr;
}
提示2
将list
参数传播到arr
。
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [...arr] = list; // change this
// change code above this line
return arr;
}
提示3
使用,,
排除arr
数组的前两个元素。
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [,,...arr] = list; // change this
// change code above this line
return arr;
}
剧透警报 - 提前解决!
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [a, b, ...arr] = list;
// change code above this line
return arr;
}