Pakalu Papito Pakalu Papito - 7 months ago 34
Javascript Question

JSON: output text using jquery

how to output a JSON format using javascript or jquery? like this

var info = {
"items": {
"phone" : [
{
"product" : "iPhone 8",
"manufacturer" : "Apple",
"releaseDate" : "2018",
"price" : 499
}
]
}
};


This is the mockup to be appear! http://s32.postimg.org/gesud83np/wireframe.png

Thank you guys, you are blessed! :)

Answer

Loop through your phone items in your info.items object.

For each item, create a phone container and append it to the content

The phone properties can be accessed like this info.items[i].propertynamehere. Here is the example, you can style it how you want, and structure it how you want.

for (var i = 0; i < info.items.phone.length; i++) {
    var phone = "<div class='phone'>" + info.items.phone[i].product + "</div>";
    $("#content").append(phone);
}

This uses JQuery so make sure to include that as well. If you would prefer a pure Javascript implementation, let me know and I can provide.