Share and Learn To Write Code!

Programming articles, which help you to build your application. If something you are stuck to code and complete the program, just find here your question-related articles.

Share with   

Find the frequency counter of values in the array list using JavaScript Program

Find the frequency of values in the array list using JavaScript
JavaScript  

Here we have one example find the frequency of the similar numbers that occur in the array list.


const example = [145332455810];

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 }
0replies
Leave a reply
49
Registerd Users
92
Total Subscribers
59
Total Articles
60901
Total Views