-2

So I'm trying to parse this json data into lists on my site. However I can't seem to loop. I've looked online and nothing seems to work...

JsonData:

{"amount":4998,"users":[{"id":"765","username":"test","profileURL":"http://example.com","avatarURL":"http:///example.com"},{"id":"765","username":"test","profileURL":"http://example.com","avatarURL":"http://example.com"}]}

I want to loop users and then get id, username etc...

jdne
  • 31
  • 1
  • 1
  • 6
  • 2
    Possible duplicate of [How do I loop through or enumerate a JavaScript object?](http://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object) – nicael Jun 18 '16 at 18:56
  • I've looked at that but because of the first part the amount, I can't seem to do obj.users and loop that... – jdne Jun 18 '16 at 18:59
  • Then loop through obj.users? – nicael Jun 18 '16 at 19:00
  • Whenever I do that it comes up with nothing. Its just blank data... – jdne Jun 18 '16 at 19:02

1 Answers1

7
obj.users.forEach(function(user) {
  console.log(user.username);
});

With a basic for loop:

for (var i = 0; i < obj.users.length; i++) {
    var user = obj.users[i];
    console.log(user.username);
}
Matis Lepik
  • 1,140
  • 2
  • 9
  • 18