I created an array from letters of a large string. Now I want to create an object which says how many times that letter is repeated in the array, but I can`t find a solution, please help me out a little.
This is what I done so far:
var str = "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Illo commodi sint fuga autem nobis atque possimus";
var arr = str.split("");
arr.forEach(function(e, i) {
if (e === " ") {
//var index = arr.indexOf(e);
arr.splice(i, 1);
}
});
var obj = {};
var counter = 0;
arr.forEach(function(e, i) {
obj[e] = 1;
});
arr2 = Object.keys(obj);
var counter = 0;
for (let c = 0; c < arr.length; c++) {
for (let b = 0; b < arr2.length; b++) {
if (arr2[b] == arr[c]) { // to find coincidences
count++;
// I'm lost here ..
}
}
}
forEachloop won't work correctly. Usearr.filterinstead.forEachloop.