如何获取本地存储数组的索引并将其与过滤后的数组一起使用?

How can I get the index of a localstorage array and use it with a filtered array?

我在这里使用 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。

找到了:

让 sortOrder = list.indexOf(object);

    list.filter((object, index) => {
        let id = object.id;
        let name = object.name;
        let sortOrder = index;
    })

默认 array.filter() 方法 returns 索引。 您不必再次找到 indexOf。

for more info refer this link