Javascript 通过动态更改的变量键访问对象键

Javascript 通过动态更改的变量键访问对象键,javascript,arrays,object,vue.js,Javascript,Arrays,Object,Vue.js,我不知道如何在标题中正确解释,但情况如下: 有三个可用角度:前、左和右: captures: { front: { img: '', correct: false }, left: { img: '', correct: false }, right: { img: '', correct: false } }, 我已经定义了一个名为this.currentAngle='front'的默认变量 我想从当前角度中的捕获对象列表中访问一个值 这不起作用: this.captures.[

我不知道如何在标题中正确解释,但情况如下:

有三个可用角度:前、左和右:

captures: {
  front: { img: '', correct: false },
  left: { img: '', correct: false },
  right: { img: '', correct: false }
},
我已经定义了一个名为this.currentAngle='front'的默认变量

我想从当前角度中的捕获对象列表中访问一个值

这不起作用:

this.captures.[this.currentAngle].img
从逻辑上讲,这个也不是

this.captures.this.currentAngle.img

正确的方法是什么?

您几乎成功了,只需从第一次尝试中删除开口方括号前的点:

const捕获={
前:{img'f',correct:false},
左:{img'l',correct:false},
右:{img:'r',correct:false}
}
让prop=‘front’

console.log(捕获[prop].img)
this.captures[this.currentAngle].img
几乎:this.captures[this.currentAngle]。img@connexo哦,你的打字速度快!!!;)