let targetted_array = [3,4,3,23,452,5,3,3,21,1,5,5];
function countInArray(array, element) {
let repeat_count = 0;
for (let i = 0; i < array.length; i++) {
if (array[i] === element) {
repeat_count++;
}
}
return repeat_count;
}
countInArray(targetted_array, 3) // will return 4. cuz "3" was repeated 4 times in the targetted_array
countInArray(targetted_array, 5) // will return 3. cuz "5" was repeated 3 times in the targetted_array
const arr = ["a", "b", "c", "d", "e", "a", "b", "c", "f", "g", "h", "h", "h", "e", "a"]
const counts = {};
arr.forEach((x) => {
counts[x] = (counts[x] || 0) + 1;
});
console.log(counts)