javascript - How to display json data in a div when json data is in array -
"data": [ { "name": "rehan", "location": "pune", "description": "hello hi", "created_by": 13692, "users_name": "xyz", }, { "name": "sameer", "location": "bangalore", "description": "how you", "created_by": 13543, "users_name": "abc", },
the api contain more 100 data, how can display these data in html page. this:
name: rehan location: pune description: hello hi created by: 13692 user name: xyz
how this?
var data = [ { "name": "rehan", "location": "pune", "description": "hello hi", "created_by": 13692, "users_name": "xyz", }, { "name": "sameer", "location": "bangalore", "description": "how you", "created_by": 13543, "users_name": "abc", }, ] var htmltext = ''; ( var key in data ) { htmltext += '<div class="div-conatiner">'; htmltext += '<p class="p-name"> name: ' + data[key].name + '</p>'; htmltext += '<p class="p-loc"> location: ' + data[key].location + '</p>'; htmltext += '<p class="p-desc"> description: ' + data[key].description + '</p>'; htmltext += '<p class="p-created"> created by: ' + data[key].created_by + '</p>'; htmltext += '<p class="p-uname"> username: ' + data[key].users_name + '</p>'; htmltext += '</div>'; } $('body').append(htmltext);
this output to:
name: rehan location: pune description: hello hi created by: 13692 username: xyz name: sameer location: bangalore description: how created by: 13543 username: abc