Javascript collection

后端 未结 5 1307
南笙
南笙 2020-12-12 09:49

sorry for noobie question. Can you explain please, what is the difference between:

1. var a = [];
   a[\'b\'] = 1;

2. var a = {};
   a[\'b\'] = 1;
         


        
5条回答
  •  隐瞒了意图╮
    2020-12-12 10:00

    I would use an array of objects:

    collection = [ 
        { "key":"first key", "value":"first value" }, 
        { "key":"second key", "value":"second value" } 
    ];
    

    etc

提交回复
热议问题