Get or set element in a Javascript ES6 Map?
问题 Is it possible to find or add an element in one step in a Javascript Map? I would like to do the following in one step (to avoid looking twice for the right place of the key): // get the value if the key exists, set a default value otherwise let aValue = aMap.get(aKey) if(aValue == null) { aMap.set(aKey, aDefaultValue) } Instead I would like to search for the key only once. In c++, one can use std::map::insert() or std::map::lower_bound() In javascript the code could look like this: let