从Javascript对象中检索值

时间:2015-07-31 11:00:18

标签: javascript

如何从下面的对象中检索值?

var recipe= {};
recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[0, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[1, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;
recipe[1, 'prodmem_active.tpoint_prod[1].setpoint'] = 1300;
recipe[2, 'prodmem_active.tpoint_prod[0].setpoint'] = 1500;
recipe[2, 'prodmem_active.tpoint_prod[1].setpoint'] = 1200;

e.g。 alert(recipe[1]['prodmem_active.tpoint_prod[1].setpoint'])不起作用。

1 个答案:

答案 0 :(得分:2)

您必须首先正确分配值。

逗号运算符评估为右侧。

此:

recipe[0, 'prodmem_active.tpoint_prod[0].setpoint'] = 1600;

表示与:

相同
recipe['prodmem_active.tpoint_prod[0].setpoint'] = 1600;

您正在尝试创建一个新对象,然后为其中一个新对象属性分配值。

recipe[0] = {};
recipe[0]['prodmem_active.tpoint_prod[0].setpoint'] = 1600;
相关问题