jquery - Distinct values in dropdown from JSON object -


i trying exttract distinct values drop down list using following code not bringing in unique strings, can please?

function build_refinesearch_cancer_combo() {

    $('#combolist-cancer-type').empty();     var list = [];     var htmlresults = '<option value="-1" selected>select cancer type_</option>';     (var = 0; < user.length; i++) {          cancerid = user[i].fkcancertypeid;         cancer = user[i].cancer;         if (cancer != list) {          htmlresults += '<option value="' + cancerid + '">' + cancer + '</option>';         list = cancer;         }     }     $('#combolist-cancer-type').append(htmlresults);  } 

$('#combolist-cancer-type').html(function() {     var ret = '<option value="-1" selected>select cancer type_</option>',         u   = user.slice(),         arr = [];      (function get() {         if (u.length) {             var v = u.shift();             if ( $.inarray(v.fkcancertypeid, arr) == -1 ) {                 arr.push(v.fkcancertypeid);                 ret += '<option value="' + v.fkcancertypeid + '">' + v.cancer + '</option>';             }             get();         }     }());      return ret; }); 

fiddle


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -