JSFiddle - React, Tailwind, and code Playground
by akhildev
JavaScript
let arr = [1,2,3,4,2,3,1,2,3,1,1];
let tempArr = [];
let maxValue = 0;
let maxIndex = 0;
arr.forEach( (val) => {
if( !tempArr[ val ] ){
tempArr[val] = 1;
} else {
let count = tempArr[val];
tempArr[val] = count+1 ;
}
if( tempArr[val] > maxValue ){
maxValue = tempArr[val];
maxIndex = val;
}
});
console.log(`Highest Repeating value is ${maxIndex}, count ${maxValue}`);