• for문 + indexOf()

중복값의 인덱스 번호를 duplication 배열에 담는다.

const arr = ['a', 'b', 'c', 'c', 'd', 'e', 'a', 'a']
const duplication = []

for(let i = 0; i < arr.length; i++) {
    if(arr.indexOf(arr[i]) !== i) {
        duplication.push(i)
    }
}

duplication // [3, 6, 7]

+ Recent posts