如果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
})
答案 0 :(得分:2)
当我只有子键的值
时
你走了:
let someObj: any = {
'somekey': 'someval'
}
let whatYouHave = 'someval'
Object.keys(someObj).forEach((key) => {
if (someObj[key] == whatYouHave){
console.log('found Key!', key); // somekey
}
})