开发者

Applying loop to a data retrieved as json

I've data returned in json as {"id":["update1","update2"]} called using jQuery Ajax().

I want to display the values in a list and to do that, I want to determine the number of time the loop should go; something like

while (count < n开发者_如何转开发umber of data under id) {
  $('#test').append(data.id[count]);
  count++
}

So here, how do I determine the number of times the loop should take place?

I tried using hasProperty but not sure to which object should I apply it!!


Try this:

$.each(data.id, function(index, value) {
    $('#test').append(value)
})

Or, indeed:

$(data.id).appendTo('#test')

Of course, to answer your original question:

console.log(data.id.length);


Here is the sample code:

var json_data = {
    id: ['a','b','c','d','f']
}

alert(json_data.id.length);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜