gpt4 book ai didi

javascript - 从 Javascript 对象中检索值

转载 作者:行者123 更新时间:2023-12-02 15:53:00 25 4
gpt4 key购买 nike

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

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;

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

最佳答案

您必须首先正确分配该值。

逗号运算符的计算结果是其右侧。

这个:

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;

关于javascript - 从 Javascript 对象中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31744559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com