我有一个未设置数量的数组。假设我要选择项目3 - the end of the array
。我该怎么做?
您也可以使用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帮助我解决这个问题