none
Loop through json result in javascript object model RRS feed

  • Question

  • Hi,

    How to loop through the json object in javascript client object model

    I have the below code, but the resultset can vary from 0 to "n" .

    $.ajax({
    			url: resurl,
    			method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {	 	 
    var items = data.d.results;
    //How to loop through items
    }

    The "items" can have multiple length .

    How to loop through the items length?

    Thanks

    Tuesday, December 27, 2016 5:01 AM

All replies

  • A simple approach would be

    $(items).each(function(i){items[i]["YourColumnName"]});

    Hope this helps.


    Regards, Huzefa Mala, MCPD, MCT Please mark the post that answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.

    Tuesday, December 27, 2016 5:25 AM
  • Hi Venkatzeus,

    We can use Jquery each function to loop the data array like below:

    jQuery.ajax({
        type: 'POST',
        url: '<?php echo admin_url('admin-ajax.php'); ?>',
        data: data, 
        dataType: 'json', // ** ensure you add this line **
        success: function(data) {
            jQuery.each(data, function(index, item) {
                //now you can access properties using dot notation
             console.log(item);
            });
        },

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, December 28, 2016 5:54 AM