0
Remove objects from array
How can i filter objects from an array using filter function and a second array with indexes properties? E.g. const arr1 =[ {obj:1,val:1},{obj:2,val:2},{obj:3,val:3},{obj:4,val:4}]; const arr2 = [2,3] I want to remove the objects with index 2 and 3 from arr1 using filter function.
4 Antworten
+ 4
Three arguments are passed to the function when using the filter method: current value, current index, the array that called the method(to keep it simple).
arr1.filter(
(v , index) => !arr2.includes(index)
)
Wagner Alves dos Santos Welcome😃
+ 6
Pls tag programming language you use
+ 1
Just like that! Omg thank you so much!
0
Javascript