在for循环中检查重复项

I know this can be done using a for loop like so for(let i = 0; i < movies.length; i++) but can it also be done in a for of loop?

这是我尝试过的:

const movies = [{title: 'One'}, {title: 'two'}, {title: '1'}]
console.log('---------------------------')
try{
    for (const movie of movies){
        let i = 0
        console.log('i =', i)
        console.log(movie.title, ' = ',movies[i + 1].title)
        // console.log('movies', movies[i + 1].title)

        if(movie.title === movies[i + 1].title){
            console.log('DUPLICATE')
        }
    i = i + 1
    }
} catch (err){
  console.log(err.message)
}

结果:

"i =" 0
"One" " = " "two"
"i =" 0
"two" " = " "two"
"DUPLICATE"
"i =" 0
"1" " = " "two"```

Edit: There should be no duplicates but result says there is.
评论