Twitter API:
https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/introduction
In theory, when there is no data, it should leave the value as empty. As seen in this part of the script:
if (
obj_data.data[int_i].entities.hasOwnProperty("urls") &&
Array.isArray(obj_data.data[int_i].entities.urls) &&
obj_data.data[int_i].entities.urls[0].expanded_url != undefined
) {
array_Expanded_url.push([obj_data.data[int_i].entities.urls[0].expanded_url]);
} else {
array_Expanded_url.push([""]);
}
But this error alert appears:
TypeError: Cannot read property 'hasOwnProperty' of undefined
And the error appears obviously indicating this line:
obj_data.data[int_i].entities.hasOwnProperty("urls") &&
How could I modify my script so that this doesn’t happen anymore?
2
Answers
Just check the chain for truthy values
or the more concise (thank you @Scotty Jamison)
and you can see where things are breaking down
ex output:
false false true true
Check for null or undefined values