Find the frequency counter of values in the array list using JavaScript Program
Find the frequency of values in the array list using JavaScript
Here we have one example find the frequency of the similar numbers that occur in the array list.
const example = [1, 4, 5, 3, 3, 2, 4, 5, 5, 8, 10];
const obj = {};
for (let index = 0; index < example.length; index++) {
const element = example[index];
obj[element] = (obj[element] || 0) + 1;
}
console.log("The Frequency of the numbers in array is: \n");
console.log(obj);
Output of the program is :
The Frequency of the numbers in array is:
{ '1': 1, '2': 1, '3': 2, '4': 2, '5': 3, '8': 1, '10': 1 }
Popular Post

Sign in to stay updated on your professional world.
Pro Code Programming
Share and learn to code!
Programming articles, which helps you to build your application.
If something you are stuck to code and complete the program, just find here your quetion related articles.