I am using Angular and Typescript here.
Let's say I have an array in localstorage called list and i want to filter out some values and also use it's index to set a value also like this.
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
})
it's late in the day and I am not sure how i could do this with ES6 or Angular.
list.filter((object, index) => {
let id = object.id;
let name = object.name;
let sortOrder = index;
})
By default array.filter() method returns the index. You don't have to find the indexOf again.