我在这里使用的是Angular和Typescript。
假设我在localstorage中有一个名为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来做到这一点。
list.filter((object, index) => {
let id = object.id;
let name = object.name;
let sortOrder = index;
})
默认情况下,array.filter((方法返回索引。你不必再找到indexOf。
有关更多信息,请参阅此链接
找到它:
let sortOrder=list.indexOf(object(;