Iterating over nested Json array -


new in json , js, appriciate if teach me bit. json array:

var info = [ {"t":"09:00","b":"vaba"}, {"t":"09:30","b":"vaba"}  ] ; 

and js part:

var output='';       (var = 0; <= info.length; i++) {     (info.t of info[i] ) {         output += '<option> '  + info[i].t + ' ' + info[i].b + '</option>';  } };      var update = document.getelementbyid('start_time');     update.innerhtml = output; 

the result in html looks this:

<option>9.00 vaba</option> <option>9.00 vaba</option> <option>9.30 vaba</option> <option>9.30 vaba</option>  

this working solution have found far, don't need double list (time , text string twice). writing function instead of second loop ends error info[i] undefined...

thanks ahead.

just remove for loop. careful referencing out-of-bounds index in info. when i = info.length, info[i] out of bounds. make sure never gets far:

var output='';       (var = 0; < info.length; i++) {     output += '<option> '  + info[i].t + ' ' + info[i].b + '</option>';   }  var update = document.getelementbyid('start_time'); update.innerhtml = output; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -