I am trying to check the values returned from a query. This result is in JSON format. My code works, until my condition statement.
While debugging I found that my condition statement was always failing because the value I am trying to retrieve from JSON and compare is always undefined.
var promise = insertDataInMongo([body, token]);
var newBody = JSON.parse(body);
if (newBody.paging.facebookPost !== -1 || newBody.paging.youtube !== -1 || newBody.paging.twitter !== -1 || newBody.paging.facebook !== -1 || newBody.paging.reddit !== -1 || newBody.paging.youtubeComment !== -1 || newBody.paging.news !== -1)
promise.then(getAthleteMedia([athlete, token, newBody.paging.facebook, newBody.paging.facebookPost, newBody.paging.reddit, newBody.paging.youtube, newBody.paging.youtubeComment, newBody.paging.twitter, newBody.paging.news]))
The body that gets returned looks like this:
{ "paging": [
{
"youtubeComment": -1
},
{
"youtube": -1
},
{
"twitter": -1
},
{
"facebook": -1
},
{
"reddit": -1
},
{
"facebookPost": -1
},
{
"news": -1
}
]}
When I debug, I see the following:
However, the parse values are showing as:
Any help is much appreciated. Thanks,