javascript - Why is my duplicate removal script not capturing unique values -
i'm trying removal duplicates sorted list.
i wrote script.
for(var = 0; < duplicateauthors.length - 1; i++){ if(duplicateauthors[i] == duplicateauthors[i + 1]) { continue; } else{ uniqauthors.push(duplicateauthors[i]); } }
it works except not capture unique values in list. doing wrong?
var uniqauthors = []; for(var = 0; < duplicateauthors.length; i++){ if(uniqauthors.indexof(duplicateauthors[i]) == -1) { uniqauthors.push(duplicateauthors[i]); } }
the above code checks whether object exist in array or not, if not add array. hence, @ end have array of unique values.
Comments
Post a Comment