function repeat_word(str) { let strArr = str.split(' '); console.log('原始数组:' + strArr + ' 长度:' + strArr.length); let tally = {}; //统计 for (let i = 0; i < strArr.length; i++) {//遍历所有的word let word = strArr[i]; if (tally[word]) { //判断是否存在 tally[word] += 1; } else { tally[word] = 1; } } for (let word in tally) { if (tally[word] > 1) { console.log(word); } }; } // let str = prompt('输入') || ''; let str = 'abc abc dsfs fdsf'; repeat_word(str);