天天看點

當JS對象屬性點後面的屬性想用變量表示時代碼該如何寫

var zhenniu={
  nextPage:{
    GFQ1:"test1",
    GFQ2:function(){
      return "test2";
    }
  }
};

console.log(zhenniu);
console.log(zhenniu.nextPage);
console.log(zhenniu.nextPage.GFQ1);
console.log(zhenniu.nextPage['GFQ1']);
console.log(zhenniu.nextPage.GFQ2());
console.log(zhenniu.nextPage['GFQ2']());           

複制