jquery – json null check not working – Education Career Blog

I am doing the following null check , even thought the object is null its still unable to check that

if(callbackResults.Details0.Tags!='') // Tags are coming as null from backend..

details is a json object. Tags is again a object array inside details.

the above null check is failing and its going inside the loop

can you tell whats going wrong there.


You can’t test for null by comparison with an empty string. Try this:

 if (callbackResults.Details0.Tags) {
   // not null


That is a check to see if Tags is an empty string. A check for ‘not null’ in JavaScript is this:


Note that this also checks for a booean ‘true’ condition, but this is the common way to make sure something is not null in javascript.


Changing the if should do it, as described above. Else, if Tags is an array, you might check if the length is larger than zero:

if(callbackResults.Details0.Tags.length > 0)

Leave a Comment