JS associative arrays: add new pair

前端 未结 2 2033
无人共我
无人共我 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.

    0 讨论(0)
  • 2021-02-19 16:29

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

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

    0 讨论(0)
提交回复
热议问题