亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to get the child nodes of Object through parameters?
伊謝爾倫
伊謝爾倫 2017-06-26 10:58:59
0
3
897

code show as below:

let china = {
    zhejiang: {
        hangzhou: 'xihu'
    }
}

// xihu
console.log(china.zhejiang.hangzhou)
// xihu
console.log(china['zhejiang']['hangzhou'])

// 能否通過 key 來訪問 china 使之能輸出 xihu
console.log( china[key] )
伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。

reply all(3)
迷茫
let china = {
    zhejiang: {
        hangzhou: 'xihu'
    }
};

//改造結(jié)構(gòu)
Object.keys(china).forEach(function(key){
    Object.keys(china[key]).forEach(function(subkey){
        china[subkey] = china[key][subkey];
    });
});

console.log( china['hangzhou'] );
/*
    xihu
*/
扔個三星炸死你

Is this what you mean?

let key = 'zhejiang';
console.log( china[key] )

Is this still the case? es2015 allows using variables as keys:

var b = 'foo';
var o ={
    [b] :'aa'
};
o[b]//aa

If not, just china[key], keywill report an error because it is not defined

ringa_lee

This cannot be done unless you use for...in to traverse and output xihu

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template