I am building some objects in JavaScript and pushing those objects into an array, I am storing the key I want to use in a variable then creating my objects like so: 我正在用JavaScript构建一些对象并将这些对象推入数组,将要使用的键存储在变量中,而后像下面这样建立对象: 数组
var key = "happyCount"; myArray.push( { key : someValueArray } );
but when I try to examine my array of objects for every object the key is "key"
instead of the value of the variable key. 可是,当我尝试检查每一个对象的对象数组时,键是"key"
而不是变量键的值。 Is there any way to set the value of the key from a variable? 有什么方法能够经过变量设置键的值吗? app
Fiddle for better explanation: http://jsfiddle.net/Fr6eY/3/ 小提琴以得到更好的解释: http : //jsfiddle.net/Fr6eY/3/ ui