How to fill a Javascript object literal with many static key/value pairs efficiently?

前端 未结 5 1808
-上瘾入骨i
-上瘾入骨i 2021-01-31 15:36

The typical way of creating a Javascript object is the following:

var map = new Object();
map[myKey1] = myObj1;
map[myKey2] = myObj2;

I need to

5条回答
  •  星月不相逢
    2021-01-31 16:14

    The syntax you wrote as first is not valid. You can achieve something using the follow:

    var map =  {"aaa": "rrr", "bbb": "ppp" /* etc */ };
    

提交回复
热议问题