var map = {};
map[key] = value;
How can I
You can check if the object doesn't have the specific key and set it or increase existing key value by one:
function assignKey(obj, key) {
typeof obj[key] === 'undefined' ? obj[key] = 1 : obj[key]++;
}
var map = {};
assignKey(map, 2);
assignKey(map, 2);
assignKey(map, 4);
assignKey(map, 1);
assignKey(map, 2);
assignKey(map, 5);
assignKey(map, 1);
console.log(map);