I want to check condition inside array with single object.
let arr = [
{
name: "john",
description: {
height: 5.5,
weight: 54,
},
},
{
name: "mary",
description: {
height: 5.8,
weight: 65,
},
},
{
name: "smith",
description: {
height: 6.1,
weight: 85,
},
},
];
let obj = {
height: 5.8,
weight: 65,
};
i want to compare the obj within the array and if its match one, i want to get the name. for ex, obj is equal to marry. i want to print mary. This is what i have tried.
let result = arr.filter((item) => item.description === obj )
console.log(result.name);
item.name === 'mary'?item.description === objwill be false, even if the key value pairs of both objects match.item.description.height === obj.height && item.description.weight === obj.weight