慕神8447489
用for循环的话,需要在for外面定义一个变量作为标志位:const arr = [1, 2, 3, 5, 6, 6 , 7];let has = false;for(let i = 0; i < arr.length; i++) { if (arr.indexOf(arr[i]) !== i) { has = true; break; }};if (has) { console.log('x');} else { console.log('y');}如果支持ES6的话,可以用Set给数组去重,然后判断两个数组长度:const arr = [1, 2, 3, 5, 6, 6, 7];const arr1 = Array.from(new Set(arr));console.log(arr.length === arr1.length);