<script> var obj = [1,4,2,1,3,2,1,4]; var o = {}; for (var index in obj){ if(o.hasOwnProperty(obj[index])){ var obj1 = obj[index]; o[obj1] = o[obj1]+1; }else{ var obj1 = obj[index]; o[obj1] = 1; } } // console.log(o); for(k in o){ console.log(k+"出现了"+o[k]+"次") } </script>