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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -