배열 에 중복 되 는 요소 가 있 는 지 확인 하기 (js)

const array = ['a', 'b', 'c'];  //    

function checkRepeat(array) {
  const temp = {};                //    
  const repeat = {};              //      
  for (const i of array) {
    if (temp[i]) {
      repeat[i] = true;
    } else {
      temp[i] = true;
    }
  }
  return repeat;
}

좋은 웹페이지 즐겨찾기