0

I need help parsing the friendsList object returned by [below] into JavaScript.

FB.api('me/friends', function(response) {});

I want to parse "response" into an array I tried response.forEach ...

I got:

Uncaught TypeError: friendsObject.forEach is not a function

So I thought I could just do JSON.parse(response); that also gave me an error.

Then I tried to print out with console.log(response) as it gives me an Object.

I am super confused why the object cant turn into an array, wont parse but prints the entire object when I console.log it.

How do I parse that object into a javascript array?

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
  • 2
    You don't need to parse anything - you just need to access the correct property in the object, that holds the _data_ ... – CBroe Feb 24 '17 at 17:50

1 Answers1

0

Always use console.log to see the actual content of the response object. It is usually an object with a "data" array, so it would be like this:

response.data.forEach...

Do not forget about error handling, response.data can be undefined too.

andyrandy
  • 72,880
  • 8
  • 113
  • 130