问题
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