How to use jQuery .each() with json value

I am reading an json file values but not i have to show the values in HTML table structure. I want to loop through the .each () method and then show the values. Please help me?

looking at jquery docs:

we are given the code:

var obj = {
  "flammable": "inflammable",
  "duh": "no duh"
$.each( obj, function( key, value ) {
  alert( key + ": " + value );

we can use the same code for a json file.

i found some json data online, combined with the each documentation it was pretty easy:,js,console

1 Like

jQuery each is used for looping. First use .getJSON to fech json file data like this:

$.getJSON("demo_ajax_json.js", function(result){
       $.each(result, function(i, field){
            //create table

Now inside the function(result){} call jQuery each method to loop through the data. Now to make a table of data use .append() method adding ‘tr’ & ‘td’ on every loop.

Basically I am giving you some ideas which you can apply and do this.

1 Like

thank you for the explanation.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.