I have 2 array of objects:
marketingCarriers:
[
{
code: "AM"
logo: "logo1.png"
name: "AEROMEXICO"
}
]
operatingCarriers:
[
{
code: "DL"
logo: "logo12.png"
name: "DELTA"
},
{
code: "AM"
logo: "logo1.png"
name: "AEROMEXICO"
}
]
I want to make an array by comparing these two array of objects where I will put the unique objects from these 2 arrays. So the output will be:
newArray:
[
{
code: "DL"
logo: "logo12.png"
}
]
What should be the process?
const operators = operatingCarriers.filter(operating =>
marketingCarriers.some(marketing => marketing.code !== operating.code),
);
const hasUniqueCarriers =
JSON.stringify(operatingCarriers) !== JSON.stringify(marketingCarriers);
{hasUniqueCarriers && operators.length > 0 && (
<div className="flight__operating-carrier-info">
<div>{I18n.t('components.flight_info.operated_by')}</div>
<div className="flight__operating-carrier-list">
{operators.map(carrier => (
<div>{carrier.name}</div>
))}
</div>
</div>
)}