Is there a way I can dynamically add data to a map in javascript. A map.put(key,value)
? I am using the yui libraries for javascript, but didn't see anything there to support this.
This question is related to
javascript
data-structures
maps
yui
Javascript now has a specific built in object called Map, you can call as follows :
var myMap = new Map()
You can update it with .set :
myMap.set("key0","value")
This has the advantage of methods you can use to handle look ups, like the boolean .has
myMap.has("key1"); // evaluates to false
You can use this before calling .get on your Map object to handle looking up non-existent keys
Source: Stackoverflow.com