0

I am working on the below code. Why am I 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[i][0].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>

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Because can't loop in for yor code shoul be below

for (i = 0; i < article.articles[0].length; i++) {

1 Comment

Sorry it was my fault @kharhys 's answer is correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.