I try to display all the parameters, but $ .each only draws the last one, although everything is in the console.

$.each(data, function(index, person) { var output = "<tr>"; output += "<td>" + person.name + "</td>"; output += "<td><select name='persons[]'>"; $.each(person.variants, function(i,value){ output += "<option>" + value.name + "</option>"; }); output += "</select></td>"; output += "</tr>"; console.log(filter); $('#results').html(output); }); 

Why does he display only the last value, but not all that exist?

    2 answers 2

    Because every time you overwrite your result in the string:

     $('#results').html(output); 

    What would work, make an addition.

     $('#results').html($('#results').html() + output); 

      It displays each value, but you immediately erase it next (and do not have time to read it :)).

       var output = ""; $.each(data, function(index, person) { output += "<tr>"; ... }); $('#results').html(output); 

      PS What is a filter ?

      • There is) I accidentally inserted it from another code here accidentally)) It does not work with your advice. With the bottom answer, everything turned out - Alex_01
      • @ Alex_01 - It happens. Must go out. Good advice - do not hesitate. Good luck. - Igor
      • thanks) i will use your advice - Alex_01