我有一个 javascript 对象,我将其用作具有键值对的映射类型。
当从控制器向其注入值时,会出现此映射的填充:
var people = {"2":"Brad","3":"Antonio","5":"Stacy","6":"Marry","1":"Jim"}
我想创建一个新对象,但还有一个条目,即伪代码
var new_people = people + {11: "John"}
我试着先把人复制给新人,然后:
new_people.\"11\" = "John"
和
new_people."11" = "John"
两者都会产生失败。虽然任何字符串而不是数字都有效,即
new_people.anystring = "John"
var new_people = {"2":"Brad","3":"Antonio","5":"Stacy","6":"Marry","1":"Jim", "anystring":"John"}