What is the most efficient way to compare arrays of objects and return only the matches?
How to find and return a new array of only the matches that has matches of color & id;
The rest of the properties can be anything else.
Example:
Then the newly created array would be...
Is the best way really just to iterate through both arrays and check the specified properties and if they match push the the match into a new array? That's the way I'm about to go for now I think...
Thanks for reading. :popcorn:
How to find and return a new array of only the matches that has matches of color & id;
The rest of the properties can be anything else.
Example:
Code:
const a = [{color:'blue',id:5}, {color:'red',id:7, type:4}, {color:'green',id:7}, {color:'blue',id:20}];
const b = [{color:'red',id:12}, {color:'green', id:7, tag:'extraData'}, {color:'red', id:7, type:4}];
Then the newly created array would be...
Code:
[{color:'green',id:7}, {color:'red',id:7}]
Is the best way really just to iterate through both arrays and check the specified properties and if they match push the the match into a new array? That's the way I'm about to go for now I think...
Thanks for reading. :popcorn: