I want to achieve a javascript program that count through a word and return the word and the number of times it appears eg {hello : 2, "@hello":1, world : 1, toString:1}
below is my code but i only get the total number of words
function words(str) {
app = {};
return str.split(" ").length;
}
console.log(words("hello world"));