Here's my structure:
var obj = {
apple: {
name: "Apple Juice",
description: "",
},
orange: {
name: "Orange Juice",
description: "",
}
}
I want to find out the description of apple
or orange
by its name without using the parent (obj.apple.description
)
Is there something like obj.apple.name.siblingProperty
to get the value of description
using name
?
You can loop through the object keys, find the index of
name
in that object, then get the next index to getdescription
: