var foo = {a: "alpha", 2: "two"};
foo[a] --> ReferenceError: a is not defined
foo[2] --> "two"
foo.a --> "alpha"
console.log(foo.2) --> SyntaxError: missing ) after argument list
foo["a"] --> "alpha"
foo["2"] --> "two"
Posted 小白历险记~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用对象属性相关的知识,希望对你有一定的参考价值。
var foo = {a: "alpha", 2: "two"};
foo[a] --> ReferenceError: a is not defined
foo[2] --> "two"
foo.a --> "alpha"
console.log(foo.2) --> SyntaxError: missing ) after argument list
foo["a"] --> "alpha"
foo["2"] --> "two"
以上是关于使用对象属性的主要内容,如果未能解决你的问题,请参考以下文章