Skip to content
Advertisement

Search an array of object and return new array of objects

I need some help with this. i have been trying to solve this out but i can not so what i am trying to do is I am trying to compare to array of objects blackListUser with contactUsers. if there is match i want to return white list of new users without the backlist users which is the last expected new array.

JavaScript

Advertisement

Answer

JavaScript

Using array_filter with an anonymous function ; and in_array. Read the in_array doc to see if it fits your need, since it is comparing two objects, you may use a custom function which tests only if the ids of the two objects are equal.

UPDATE

Or a version of the code which is more beginner friendly:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement