Link to home
Start Free TrialLog in
Avatar of Mark Steggles
Mark StegglesFlag for United States of America

asked on

How to loop through JSON array of objects

Hello,

I need to loop through this array.. how can I do that?

var buildCarousel = '/components/ajaxproxy/mostactive.cfc?method=getmostactive&returnformat=json';
$.getJSON(buildCarousel, function(data) {

});
JSON array of objects.

[{"P":"\/photos\/family\/173000\/173420s.jpg","L":1121895},{"P":"\/photos\/family\/173000\/173422s.jpg","L":1121887},{"P":"\/photos\/family\/173000\/173005s.jpg","L":1121876}

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

Use :


$.getJSON(buildCarousel, function(data) {
    for(i=0;i<data.length;i++) {
        alert(data[i].P);
        alert(data[i].L);
    }
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark Steggles

ASKER

Thanks :)

I was using the for loop but was incorrectly using:

data[i].L

instead of:

data[i]["L"]
You're welcome! Thanks for he points!