So I'm following some tutorials on Udemy & on the whole they have been excellent except now there is a new instructor for the part I'm on now who isn't as descriptive on the inner workings of the functions.
The current example is a function that counts how many iterations of vowels there are within said string.
function vowelCount(str){
var splitArr = str.toLowerCase().split("");
var obj = {};
var vowels = "aeiou";
splitArr.forEach(function(letter){
if(vowels.indexOf(letter) !== -1){
if(obj[letter]){
obj[letter]++;
} else{
obj[letter] = 1;
}
}
});
}
vowelCount("abcdefghij")
The part that I'm personally stumped on is if(obj[letter])
In my mind the obj variable is empty and anything within the [] in this case is a reference to an index, and I don't understand what it is the if statement is checking I also don't really understand the syntax that follows of obj[letter].
Any enlightenment on this would be highly appreciated.