JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://getfirebug.com/firebug-lite-debug.js"></script>

JavaScript

var str = "Goiaba";
var ocorrencias = {};

for(var i = 0; i < str.length; i++) {
    var n = str[i];
    ocorrencias[n] = ocorrencias[n] ? ocorrencias[n] + 1 : 1;
}

console.log(ocorrencias);