我有一个未设置项目数量的数组。假设我要选择项目3 - the end of the array
。我该怎么办?
答案 0 :(得分:0)
答案 1 :(得分:0)
您还可以使用filter
方法。
例如,如果您有以下内容:
let arr = ['bug', 'cat', 'dog', 'flea', 'bat', 'hat', 'rat'];
let newArr = arr.filter((element, index) => index >= 3);
console.log(newArr); // ['flea', 'bat', 'hat', 'rat']
您可以指定要从哪个索引选择到数组的末尾。
感谢Pointy帮助我解决此问题