javascript - Iterating jquery objects -


i attempting iterate , output values of choices property using jquery each(). code seems output array index , not string values. why this? here jsfiddle

  var allquestions = [   {     question: "who prime minister of united kingdom?",      choices: ["david cameron", "gordon brown", "winston churchill", "tony blair"],      correctanswer:0   }];    $(info[0].choices).each(function(value){     $('#answers').append($('<li>').text(value)); }); 

you have confused

$(selector).each() 

http://api.jquery.com/each/

with

$.each(array, callback) 

http://api.jquery.com/jquery.each/

you want use second form iterating on arrays.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -