How might I add check to see if a key already exists, and if does, increment the value, and if it doesn\'t exist, then set the initial value?
Something like this pseudo-
Your pseudo-code is almost identical to the actual code:
if (key in object) { object[key]++; } else { object[key] = 1; }
Although I usually write:
if (!(key in object)) { object[key] = 0; } object[key]++;