How to filter using array index in react?

let deleteLi = newlist.filter(y => y.index === i)

Second argument to the callback is the index

newlist.filter((item, index) => index === i)

But you often don’t want to mutate arrays /objects in React/Redux. This is how you can also do it:

let arr = [

const i = 1;

// ["apple", "banana", "coke"]

arr = [...arr.slice(0, i), ...arr.slice(i + 1)]

// ["apple", "coke"]

Sorry, I misspoke. I had splice on my brain. Of course filter doesn’t mutate. But I think filter is kind of a clumsy way to remove an item at an index, especially if you are dealing with a vary large array - filtering through every single element.

Thanks. I found the sol…
let deleteLi = newlist.filter((x, index, arr)=>{


 return index!==i