I'm trying to use the Object.keys(object1).find(key=> object1[key] === x) Where x is an object:
let x = {
name: "Test"
id: 1
}
The goal is to return b, because that's the corresponding key to the object x, but I can't compare x to the object within object1, because objects don't easily compare. How would I go about to include one of the solutions from the following post, inside the "Object.keys(object1).find..." function? How to determine equality for two JavaScript objects?
I have the following object:
let object1 = {
a: "123"
b: {
name: "Test"
id: 1
}
c: {
name: "John"
id: 2
}
}
Thanks in advance!