简体   繁体   中英

Adding empty key, value pair to javascript object

How can I add empty (key,value) pair to an existing object. suppose I have an object as

var map = {
    "name": "x"
};

How can I get below output

var map = {
    "name": "x",
    "": ""
};

I am looking for similar to push function in case of array.

You just need to use the [] operator, like that :

var map = {
    "name": "x"
};

map[""] = "";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM