I'm trying to return an object with each letter from a string as a key, and each key's value being the amount of times that letter appears.
The if statement doesn't seem to execute, I think it's a problem with the not operator because I can get it to execute if I remove it and put the letter in the object so that it evaluates to true.
function multipleLetterCount(str){
var countObj = {};
for(var i = 0; i < str.length; i++){
//Why won't this if statement run???
if(!str[i] in countObj){
countObj[str[i]] = 1;
} else {
countObj[str[i]]++;
}
}
return countObj;
}
multipleLetterCount("aaa")
It returns {a: NaN}