I was wondering if there is a Lodash approach to this problem, which I would otherwise solve with a for
loop. I would like to return true
if collection
contains one or more elements with nested object identical to c
.
The below example would return true
because collection[1]
contains an identical c
.
Needle:
c = {
x: 11,
y: 22,
z: 33
}
Haystack:
collection = [
{
a: 1,
b: 1,
c: {
x: 10,
y: 20,
z: 30
},
d: 1
},
{
a: 1,
b: 1,
c: {
x: 11,
y: 22,
z: 33
},
d: 1
},
{
a: 1,
b: 1,
c: {
x: 12,
y: 24,
z: 36
},
d: 1
}
]
This is different from questions such as How to do a deep comparison between 2 objects with lodash? because I need to check if any of the collection items contain an identical object nested within them, not compare whether two objects are identical to each other.
Thanks in advance for your help.