var arr = [1,null,'3',3,'3',null,[1,2],[1,2]] function fun(arr){ let map = new Map(),res=[],count=0 for(let i=0;i<arr.length;i++){ let temp = arr[i] if(map.get(temp)){ map.set(temp,map.get(temp)+1) }else{ map.set(temp,1) } count=count>map.get(temp)?count:map.get(temp) } console.log(map) for(let item of map){ console.log(item,'iii',count) if(item[1]===count){ res.push(item[0]) } } return res } console.log(fun(arr),'res')