I'm checking an Object
(like an Associative Array) to see if a portion of data is available there or not, but I'm getting an undefined
error exactly in the if
statement where I'm checking if it is undefined
or not!
I have an Object
like this:
var data = {
1: {
2: {
3: [
["a","b"],
["c","d"],
],
}
}
}
I have also tried with double-quotes
like: var data = { "1": { "2": { ...
These are the if
statements which I've already tried. All of them failed, Firebug
is generating TypeError: data[1][2][3] is undefined
exactly in the if
statement:
if (typeof data[1][2][3] == "undefined") {
if (data[1][2][3] === undefined) {
// when I have double quotes
if (typeof data["1"]["2"]["3"] == "undefined") {
if (data["1"]["2"]["3"] === undefined) {
I checked that in jsfiddle.net and it works fine. I tried all the things I could imagine of, however I still don't have any idea why it fails in the if
statement.
Update
look at this, oh god: