JS associative arrays: add new pair

前端 未结 2 2034
无人共我
无人共我 2021-02-19 15:51

I have an associative array in JS.

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

How can I add

2条回答
  •  孤街浪徒
    2021-02-19 16:23

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

    or

    array.newpair = 'newvalue';
    

    This is quite a decent read on the subject.

提交回复
热议问题