I wanted to build similar to lodash get method. Where you put the object and key name to get value if exist. I have done this but just wanted to have more better approach. Here is what has been done so bar.
var x = {
d: 'new vale',
a: {
b: {
c: {
e: 'value'
}
}
}
}
function getVal(obj, key) {
var keys = obj[key];
if (!keys) {
for (var i in obj) {
if (Object.prototype.toString.call(obj[i]) === '[object Object]') {
return getVal(obj[i], key)
}
}
} else {
return obj[key]
}
}
console.log(getVal(x, 'c'))
if (typeof obj[i] == "object")? \$\endgroup\$