I have a code written in typescript like this -
const arr = [3, 3, 2, 1, 4, 5];
const count = {};
arr.forEach((element:any) => {
count[element] = (count[element] || 0) + 1;
});
console.log(count);
The expected output is like this { '1': 1, '2': 1, '3': 2, '4': 1,
'5': 1 }
This works fine in javascript but in typescript, I am getting an error like this-
Element implicitly has an 'any' type because expression of type 'any'
can't be used to index type '{}'.
I have tried giving type of element to number also but it did not work.