function word(str){ var newStr = str.toLocaleLowerCase(); var obj = {}; var arr = newStr.split(" "); var maxWord = null; arr.map(function (t) { if(obj[t]){ obj[t].num ++; if(maxWord.num < obj[t].num){ maxWord = obj[t]; } }else { var w = { num: 1, value: t }; if(!maxWord){ maxWord = w; } obj[t] = w; } }) return maxWord } // 测试数据 var str="The indictment said said said said the be defendants had collected geographical data "+ "indicating thousands of people would be killed in the chemical blast"; console.log(word(str));