Array.prototype.slice() ,如下所示: const [a,b,... arr] = [1,2,3,4,5,7];变量
console.log(a,b); // 1,2
的console.log(ARR); // [3,4,5,7]
a和b从数组中获取第一个和第二个值。之后,由于rest操作符的存在, arr以数组的形式获取其余的值。 rest元素仅作为列表中的最后一个变量正常工作。在中,您不能使用rest运算符来捕获一个子数组,该子数组会遗漏原始数组的最后一个元素。 Array.prototype.slice()以便arr是原始数组source的子数组,省略前两个元素。 arr应为[3,4,5,6,7,8,9,10]'
testString: 'assert(arr.every((v, i) => v === i + 3) && arr.length === 8,"arr should be [3,4,5,6,7,8,9,10]");'
- text: 应该使用解构。
testString: 'getUserInput => assert(getUserInput("index").match(/\[\s*\w*\s*,\s*\w*\s*,\s*...\w+\s*\]/g),"Destructuring should be used.");'
- text: 不应使用Array.slice() 。
testString: 'getUserInput => assert(!getUserInput("index").match(/slice/g), "Array.slice() should not be used.");'
```