I am facing some issue on using .map and .filter where I am unable to get the object which is not similar in two objects.
What changes I need to do to get the uncommon object from arrayObjTwo.
code
const arrayObjOne = [{
countryCode: "US",
description: " Backyard of home",
id: "1234",
location: "US",
name: "Backyard",
}]
// Array Object 2
const arrayObjTwo =[
{ description: "Backyard of home", spaceName: "Backyard" },
{ description: "Frontyard of home", spaceName: "Frontyard"},
]
const object1Names = arrayObjOne.map(obj => obj.Name); // for caching the result
const results = arrayObjTwo.filter(name => !object1Names.includes(name));
console.log(results);
One compiler code: https://onecompiler.com/javascript/3xy92hpmp
expected result:
const arrayObjTwo =[
{ description: "Frontyard of home", spaceName: "Frontyard" }
]
Thanks..
spaceName!==namenameinstead ofNamein the mapobject2and there's nothing calledobject2in your code. Your question would be more clear if you referred to things by the same name in your question text and in your code.