有两种方法可以访问对象的属性:
- 点表示法:
something.bar
- 括号符号:
something['bar']
方括号之间的值可以是任何表达式。因此,如果属性名称存储在变量中,则必须使用方括号表示法:
var foo = 'bar';something[foo];// both x = something[foo] and something[foo] = x work as expected

有两种方法可以访问对象的属性:
something.bar
something['bar']
方括号之间的值可以是任何表达式。因此,如果属性名称存储在变量中,则必须使用方括号表示法:
var foo = 'bar';something[foo];// both x = something[foo] and something[foo] = x work as expected