I was testing my ajax code and noticed that I can only perform an if-defined-clause on the outer array.
To me it seems a bit redundant if I have to check all outer arrays. Imagine that there are 10 sub arrays. Could anyone confirm if this is normal, or perhaps enlighten me with a better way to check if an object is undefined? The code (the typeof part) I took from Stackoverflow as well.
if (typeof obj['item'] == 'undefined') {
//this works
} else {
//proceed
}
if (typeof obj['item']['color'] == 'undefined') {
//this does not work
} else {
//proceed
}
NOTE: Apparently it's normal (answers is "yes") Thanks Epascarello for providing the links to ways to deal with this.