How to create dictionary and add key–value pairs dynamically?

后端 未结 15 743
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 00:37

From post:

Sending a JSON array to be received as a Dictionary

I’m trying to do this same thing as that post. The only issue is that I d

15条回答
  •  萌比男神i
    2020-11-28 01:28

    An improvement on var dict = {} is to use var dict = Object.create(null).

    This will create an empty object that does not have Object.prototype as it's prototype.

    var dict1 = {};
    if (dict1["toString"]){
        console.log("Hey, I didn't put that there!")
    }
    var dict2 = Object.create(null);
    if (dict2["toString"]){
        console.log("This line won't run :)")
    }
    

提交回复
热议问题