Skip to content

re: Cannot read property 'data' of undefined VIEW POST

  1. You're getting back a string of json from the API and parsing it. let content = JSON.parse(response.body); This appears to work.
  2. Next, you're looking up items on that JSON. e.g. content[0].data.children[0].data.permalink;

My guess is that the problem is that the content array in the JSON is sometimes empty. Then when you do content[0], you're getting back the first element of an empty array, which is, understandably, undefined. Then you try to get .data on the undefined and that triggers the error.

Try putting the JSON to the console and inspecting it visually to see if it has all the fields you expect.

let content = JSON.parse(response.body)

Its saying response is not defined.

code of conduct - report abuse