get Nested Property Key By Value Comparasion
// Recursive function to get the name of property with given value from given object
const getNestedPropKeyByValueComparasion = (obj, value) => {
// Check if it's an object
if (!!obj && typeof obj === 'object') {
let keys = Object.keys(obj)
for (let key of keys ) {
if (obj[key] === value)
return key
else {
let resultInNested = getNestedPropKeyByValueComparasion(obj[key], value)
if ( !!resultInNested )
return resultInNested
}
}
}
return null
}
// Alternatively if you don't want to check deeply nested values, simply remove the else block