如何获得价值的wood
,如果我有价值的fruit
?我不知道要在哪个森林里寻找。
let oranges,cherry,deep,apples,cedar,shallow
let tree =
mountainForest: {
fruit:oranges
wood:cherry
root:deep
},
rainyForest: {
fruit:apples
wood:cedar
root:shallow
}
这是我尝试的:
var result = 'someval'
Object.keys(someObj).forEach((key) => {
// can't figure out this part
})
当我只有子键的值时
干得好:
let someObj: any = {
'somekey': 'someval'
}
let whatYouHave = 'someval'
Object.keys(someObj).forEach((key) => {
if (someObj[key] == whatYouHave){
console.log('found Key!', key); // somekey
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句