问题:
In JavaScript, I've created an object like so: 在JavaScript中,我创建了一个像这样的对象:
var data = {
'PropertyA': 1,
'PropertyB': 2,
'PropertyC': 3
};
Is it possible to add further properties to this object after it's initial creation if the properties name is not determined until run time? 如果直到运行时才确定属性名称,是否可以在初始创建此对象后为其添加其他属性? ie 即
var propName = 'Property' + someUserInput
//imagine someUserInput was 'Z', how can I now add a 'PropertyZ' property to
//my object?
解决方案:
参考一: https://stackoom.com/question/4y2l/是否可以向JavaScript对象添加动态命名的属性参考二: https://oldbug.net/q/4y2l/Is-it-possible-to-add-dynamically-named-properties-to-JavaScript-object
来源:oschina
链接:https://my.oschina.net/u/4428122/blog/4336130