0

hello I want to iterate an array of objects and render them in a table. I'm pretty new to this so im struggling to iterate over each inner object. Any help appreciated. Here is my array of objects: I can get a length of the whole array but not the length of each object(final Product). Would I iterate over the whole array and then another loop for each object inside? How do i get the length of this object inside the array and should i use a for loop or for each loop? many thanks.

var output = [finalProduct { DeviceName="gkorosi-lt2",  Product="Photoshop CC",  Status="Active"},
          finalProduct { DeviceName="gkorosi-lt3",  Product="Illustrator CC",  Status="Active"}];

2 Answers 2

1

If you whant to use JQuery, you can use $.each function

var output = [{
    finalProduct: {
      DeviceName: "gkorosi-lt2",
      Product: "Photoshop CC",
      Status: "Active"
    }
  },
  {
    finalProduct: {
      DeviceName: "gkorosi-lt3",
      Product: "Illustrator CC",
      Status: "Active"
    }
  }
];

$.each(output, function(key, value) {
  $("body").append("<div>" + value.finalProduct.DeviceName + "</div>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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

Comments

0

Thanks. I had to keep my original data structure and using these For loops, I managed to get it to work.

for (var i = 0; i < output.length; i++){
  $(".trbody").append("<td>"+ output[i].DeviceName.toUpperCase() + "</td>");
    //etc
}

Comments

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.