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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -