我在这里使用的是Angular和Typescript。
假设我在本地存储中有一个名为list的数组,我想过滤掉一些值,并使用它的索引来设置一个值,也如下所示。
list.filter((object) => {
let id = object.id;
let name = object.name;
let sortOrder = object.index?????<--- how do I get the indexed item values of this filtered array
})
时间已经晚了,我不确定如何使用ES6或Angular来做到这一点。
发布于 2019-11-02 01:23:29
list.filter((object, index) => {
let id = object.id;
let name = object.name;
let sortOrder = index;
})
默认情况下,array.filter()方法返回索引。您不必再次找到indexOf。
发布于 2019-11-01 22:45:05
找到了:
设sortOrder = list.indexOf(object);
https://stackoverflow.com/questions/58666621
复制相似问题