programming-examples/js/Array/Write a JavaScript program to find the most frequent item of an array..js

19 lines
487 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
var arr1=[3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3];
var mf = 1;
var m = 0;
var item;
for (var i=0; i<arr1.length; i++)
{
for (var j=i; j<arr1.length; j++)
{
if (arr1[i] == arr1[j])
m++;
if (mf<m)
{
mf=m;
item = arr1[i];
}
}
m=0;
}
console.log(item+" ( " +mf +" times ) ") ;