Mona Coder Mona Coder - 1 year ago 131
Javascript Question

Issue on Loading Data From JavaScript Object to Table

Can you please take a look at this demo and let me know why I am not able to load data from the

article
object to the table row?



var article = {
student: 'Eve Jackson',
studentID: 'A0088888',
articles:[[
{title : "OOP Concepts", size : "Medium", printable:true}, {tags : ["C#", "Java", "Objective-c"]}, {weight : [1, 2, 1]}, 16, {extra : [0, 1.5, 0]}
] ,
[
{title : "Functional", size : "Large", printable:false}, {tags : ["JavaScript", "HTML", "PHP"]}, {weight : [2, 2, 1]}, 16, {extra : [0, 1.5, 0]}
] ,
[
{title : "Web", size : "Small", printable:true}, {tags : ["HTML", "CSS", "Angular","jQuery"]}, {weight : [3, 2, 1]}, 16, {extra : [0, 1.5, 0]}
]
]
};

for (i = 0; i < article.articles.length; i++) {
$('#map').append('<tr><td>'+ article.articles[0][i].title+'</td></tr>');
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="width:100%">
<tr>
<th>Topic</th>
<th>Size</th>
<th>Printable</th>
<th>Tags</th>
</tr>
<tbody id="map"></tbody>

</table>




Answer Source

change article.articles[0][i].title to article.articles[i][0].title

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download