Remove array of objects from another array of objects

前端 未结 4 1894
情话喂你
情话喂你 2021-02-06 11:17

Assume we have the following arrays of objects to be compared based on property id:

a = [{\'id\':\'1\', \'name\':\'a1\'}, {\'id\':\'2\', \'name\':\'         


        
4条回答
  •  情话喂你
    2021-02-06 12:03

    Easy with new ES6 Syntax

    Second and Third way are more performant i guess....

    a.filter(i => !b.filter(y => y.id === i.id).length); // One Way
    a.filter(i => !b.find(f => f.id === i.id)); // Second Way
    a.filter(i => b.findIndex(f => f.id === i.id)) // Third Way
    

提交回复
热议问题