How to count maximum duplicate value in an array in javascript

Sujata Sharma

i want to count maximum duplicate value from array and number corresponding to it. like if i have array:- var arr=[2,1,4,3,2,8,2,9,2];

i want to display that 4 is repeating maximum time.

Thanks in advance.

rwx

You could do it e.g. with this code:

max = 0;
$.each(arr, function(){
    current_max = 0;
    current = this;
    $.each(arr, function(index, value){
    if(current==value){
        current_max += 1;
    }
  });
  if (current_max > max){
    max = current_max;
  }
});

https://jsfiddle.net/aec8nhvj/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to count duplicate value in an array in javascript

How to count duplicate value in an array and store in array

How can count duplicate array value in php?

Count duplicate values in an array and return count with an additional value using Javascript

How to count values in a javascript object (it is not an array)? [not duplicate] [not duplicate] [NOT

How to remove duplicate value in array javascript?

get every value with maximum count in a numpy array

Overwrite duplicate value in an array - Javascript

Duplicate objects in array of objects by count value

Javascript: How to remove only one value from duplicate array values

how to create a new array in Descending order of count of each duplicate value out of an old array

How to find maximum value in an array

How to find the maximum value in the array?

How count the value of array?

How to find the maximum value among a range of count

How to duplicate value of array in ruby

How to get count of duplicate values with value name

how to count duplicate elements in array in java

How to count array duplicate elements in MongoDB

how to count duplicate values of array with hashreference

How to count unique value from object of array in javascript

Duplicate in array to how to remove it - JavaScript

Javascript Array get maximum value by key

Converting duplicate object value to array Javascript

Removing duplicate key value pair in javascript array

Duplicate value in javascript array of objects is not recognized by find()

how to eliminate duplicate rows in column A keeping the maximum value in B in python

Mongo Aggregate: Sum Count Field of Duplicate Array Value Field

Check an array for duplicate values, get value and get count