判断数组中存在重复元素

let arr = [1,2,1,1,3,3,3,4,5];


console.log(arrayIsRepet(arr));
function arrayIsRepet(arr){//判断数组中存在重复元素
  let b = [];
  let c = [];
  arr.forEach(item => {
    if(c.indexOf(item) == -1){
      c.push(item);
    }else{
      b.push(item);
    }
  });
  if(b.length > 0){
    return true;
  }else{
    return false;
  }
}

原文地址:https://www.cnblogs.com/fqh123/p/14358137.html