当前位置:网站首页>JS object array de duplication

JS object array de duplication

2020-11-09 16:55:37 Luo Yihao

To array objects questions duplicate removal . if id Same value , It's the same element .

The method of de duplication is as follows :

// duplicate removal 
let arr = []
for(let i = 0;i < questions.length;i++){
    let j
    for(j = 0;j < arr.length;j++){
        if(arr[j].id == questions[i].id){
            break
        }
    }
    if(j == arr.length){
        arr.push(questions[i])
    }
}
questions = arr

 

版权声明
本文为[Luo Yihao]所创,转载请带上原文链接,感谢