Skip to content

Instantly share code, notes, and snippets.

@dwqs
Created June 28, 2017 08:07
Show Gist options
  • Save dwqs/50565af19a7d7339aef28912c6ad528e to your computer and use it in GitHub Desktop.
Save dwqs/50565af19a7d7339aef28912c6ad528e to your computer and use it in GitHub Desktop.
function getPros(o, prop){
if(o.hasOwnProperty(prop)){
return o[prop];
}
let v = null;
Object.keys(o).forEach((item) => {
if(typeof o[item] === 'object'){
v = getPros(o[item], prop)
}
});
return v;
}
let a = {t1: 1};
let b = {t2: 2};
let c = {t3: {
d: b
}};
console.log(getPros(c, 't2')) // 2
@dwqs
Copy link
Author

dwqs commented Jun 28, 2017

let b = {t2: 555};
let c = {t3: {
    d: {e:b}
}};
console.log(getPros(c, 't2')) // 555

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment