天天看点

当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']());           

复制