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.

1st Oct 2020, 5:49 AM
Wagner Alves dos Santos
Wagner Alves dos Santos - avatar
4 Respostas
+ 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😃
1st Oct 2020, 7:31 AM
Kevin ★
+ 6
Pls tag programming language you use
1st Oct 2020, 5:55 AM
WenHao1223
WenHao1223 - avatar
+ 1
Just like that! Omg thank you so much!
1st Oct 2020, 7:37 AM
Wagner Alves dos Santos
Wagner Alves dos Santos - avatar
0
Javascript
1st Oct 2020, 5:56 AM
Wagner Alves dos Santos
Wagner Alves dos Santos - avatar