JS associative arrays: add new pair

早过忘川 提交于 2019-12-05 13:50:20

问题


I have an associative array in JS.

var array = {
    'one' : 'first',
    'two' : 'second',
    'three' : 'third'
};

How can I add new pair in it


回答1:


array['newpair'] = 'new value';

or

array.newpair = 'newvalue';

This is quite a decent read on the subject.




回答2:


It's an object literal, not really an "associative array".

Just do array['something'] = 'something';



来源:https://stackoverflow.com/questions/6936636/js-associative-arrays-add-new-pair

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!