Tuesday, 15 August 2017

Use Loop to get Object JSON Content Output To HTML - W3tricks

Use Loop to get Object JSON Content Output To HTML



Index.html


<html>
<head>
<title>W3tricks</title>
</head>

<body bgcolor="#000">
<div id="output" style="color:#fff;"></div>
<br/><p>
<script src="script.js"></script>
</body>
</html>


Script.js


var student = [{"name" : "Bob", "age" : "18", "city" : "new york"}, {"name" : "Alice", "age" : "16", "city" : "paris"}, {"name" : "BEN TEN", "age" : "20", "city" : "London"}];

var con = "<h1>Student Name</h1>";

for(var x in student){
  con += student[x].name + "<br/>";
}
document.getElementById('output').innerHTML = con;

Output


0 comments:

Post a Comment