0

Using the Foreach statement as shown in the video, display all the contents of the JSON data structure into a Web page showing JSON data in a table - pulled using the Foreach instruction

studentinfo.JSON

  "categoryName": "Student Information",
  "categories": [
    {
      "studentID": "123456789",
      "firstName": "Reee",
      "lastName": "REEE",
      "address": "123 Uncreative way",
      "city": "reee",
      "state": "RRAAA",
      "zip": "55555",
      "email": "123@blaah.com",
      "phone": "123-456-5432",
      "major": "Cyber Security",
      "advisorName": "reeee Moore",
      "advisorEmail": "reee.moore@reeeeee.edu"
    }
  ]
}

school.ejs

<ul>
    <% studentinfo.categories.forEach(function(item){ %>
        <li><strong>Student ID:</strong> <%= item.studentID %> </li>
        <li><strong>First Name:</strong> <%= item.firstName %></li>
        <li><strong>Last Name:</strong> <%= item.lastName %></li>
        <li><strong>Address:</strong> <%= item.address %></li>
        <li><strong>City:</strong> <%= item.city %></li>
        <li><strong>State:</strong> <%= item.state %></li>
        <li><strong>Zip:</strong> <%= item.zip %></li>
        <li><strong>Email:</strong> <%= item.email %></li>
        <li><strong>Phone:</strong> <%= item.phone %></li>
        <li><strong>Major:</strong> <%= item.major %></li>
        <li><strong>Advisor Name:</strong> <%= item.advisorName %></li>
        <li><strong>Advisor Email:</strong> <%= item.advisorEmail %></li>

    <% }); %>
</ul>

This doesn't seem like what my teacher wants as it seems excessive. I'm trying to find the best way to implement this into a table.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Max Ja
  • 1

0 Answers0