我正在尝试创建一个过滤器,它将帮助我根据特定索引过滤掉数组中的结果。
const newArr = oldArr.filter((item, index) => for(index === selectedIndex; index < selectedIndex + 2; index ++) {
return this.createOptions(item, index, selectedItem))
};
我从代码中的事件处理程序获取 selectedIndex。我该如何写这样的案例?
最佳答案
从您的(伪)代码中不清楚您想要做什么。我最好的猜测是您想从指定索引处的数组中获取项目:
// get item at position `selectedIndex` in array
const item = oldArr[selectedIndex]
// do whatever you need with the item
this.createOptions(item, index, selectedItem)
关于javascript - 更改过滤器内的开始和结束索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50341778/