I have an array of objects as following:
const objArray = [
{scope: "xx", sector: "yy", status: "pending", country: "USA"},
{scope: "zz", sector: "yy", status: "pending", country: "USA"}
{scope: "xx", sector: "yy", status: "pending", country: "USA"}
]
And an object as following:
const compare = {scope: "xx", sector: "yy"}
or that one:
const compare = {scope: "xx"}
or that one:
const compare = {scope: "yy"}
I want to loop through the array of objects using one of those three compare
objects, and return all objects that match with any one of those three compare
examples objects with same scope
and sector
or scope
only or sector
only.
I have tried .filter()
function, but didn't get it to work:
const filteredCards = objArray.filter(card =>{
return card.scope === compare.scope
&& card.sector === compare.sector;
});