I have an ajax call to a php function that can return a string, an array, an object, or nothing. (Yes, I know it would be ideal to normalize this so there's only one possible return type, but it's a third-party library that was chosen by our lead dev, and I can't change that.) Is there an easy way I can test to see if it exists? I've tried this:
function doSomething(data) //data is what's returned by a previous ajax call
if(data.unavailableItems) {
// do something
}
}
But it's hitting the do something
even if the unavailableItems
element doesn't exist in the data array that comes into the function. I know I must be missing something really obvious, but I can't for the life of me find it.
Here's an example of the data that's coming into the function; as you can see there's no element called unavailableItems
: