javascript - Finding duplicate strings in object using $.map -


from following code expecting elist contain each string in er once. mean elist have unique value of er. not getting unique strings in elist. whats wrong here?

i = 0;  elist = ""; $.map(er, function(value, key){                               if ( isduplicate(value, er, i) < 0 ) {         elist += value;       }     $("#"+key).addclass('has-error');     += 1; });  function isduplicate(str, er_, offset){     j = 0;      return_val = -1      $.map(er_, function(value, key){         alert(j +'>'+offset+'------'+value+'=='+str);         if ( j > offset && value == str){             return_val = j;             alert('matched');         }         j += 1;     });      return return_val; } 

you can use more simple this:

var arr=[]; $.map(er, function(value, key){                if   ( arr.indexof(value) == -1 )     {arr.push(value);} }); alert(arr.join()); 

http://jsfiddle.net/7cohow41/3/


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -