An advantage of bracket notation is that we are not restricted to just using strings in the brackets. We can also use variables whose values are property names:
var someObj = {propName: someValue};
var myProperty = "propName";
someObj[myProperty]
The last line is exactly the same as using someObj["propName"].
本文介绍了在JavaScript中如何使用变量作为对象属性名称的方法。通过使用方括号表示法,可以灵活地利用变量来引用对象的属性,这种方法为动态属性访问提供了便利。

877

被折叠的 条评论
为什么被折叠?



