在循环中,我创建了以下对象,然后将其添加到全局数组中:
i++;
var objToAdd = {"code1":myvar1, "code2":myvar2, "code3":myvar3};
ary.push(objToAdd);
但是,这会向数组添加无密钥对象,如下所示:
{...
{"code1":"blah", "code2":"blah", "code3":"blah"},
{"code1":"blah", "code2":"blah", "code3":"blah"},
{"code1":"blah", "code2":"blah", "code3":"blah"},
...}
使用i
,在循环中,我想添加对象键值对,如下所示:
{...
"1":{"code1":"blah", "code2":"blah", "code3":"blah"},
"2":{"code1":"blah", "code2":"blah", "code3":"blah"},
"3":{"code1":"blah", "code2":"blah", "code3":"blah"},
...}
非常感谢。