const inventory = [
{ name: { vegetable: 'carrot' }, quantity: 2 },
{ name: { meat: 'pork' }, quantity: 0 },
{ name: { fruit: 'cherries' }, quantity: 5 },
];
const result = inventory.find(name => name === { fruit: 'cherries' });
console.log(result);
I have an array of nested objects and I'm trying to find out if there is one including the { fruit: 'cherries' } object but I get undefined as a result.
So I guess you can't pass an object as a search parameter?
{ fruit : 'cherries' } === { fruit : 'cherries'}will returnfalse. So you get undefined.