Have you tried using an object ? I find them useful for this situation.
const counter = {};
const words = ["cow","cow","cow","cow","cow","cow"];
for (let i = 0; i < words.length; i++) {
const word = words[i]; // "cow"
if (!counter.hasOwnProperty(word)) {
// if counter doesn't have a property named "cow", add it to counter and assign 1 to the property "cow"
counter[word] = 1;
} else {
// else, increment the value of "cow" by 1
counter[word]++;
}
}
console.log(counter["cow"] + " cows"); // 6 cows
But I think you should learn the splice function. You can loop and, if arr.indexOf(arr[i]) !== arr.lastIndexOf(arr[i]) you can splice that index out of the array.
You can also just create a new empty array, do a loop in the old array and if newArray.indexOf(oldArray[i]) === -1 - if the new array doesn’t have that letter, you can push it in and then return the newArray.