I am trying to count how many time the unique characters appears in a string. but I am stuck at the object iteration where the it only returns 1 no matter how many times same character appears more than one time:
function allUniqueCha(word) {
var wordObj = {};
var wordArray = word.split([, ]);
wordArray.forEach(function(c) {
wordObj[c] = +1;
});
console.log(wordArray);
console.log(wordObj);
}
allUniqueCha("Bubble")
The output is : {B:1, u:1,b:1,l:1,e:1} but the expected value of key "b" should be 2.
wordObj[c]? What happens when you assign+1to it?