I have a nested object structured like this:
- var wDefaults = {
- "pcrPortal":{
- "pcr001":{"wclosed":false,"wcollapsed":true,"pcol":0},
- "pcr002":{"wclosed":false,"wcollapsed":true,"pcol":1},
- "pcr003":{"wclosed":false,"wcollapsed":true,"pcol":2}
- },
- "pcfPortal":{
- "pcf001":{"wclosed":false,"wcollapsed":true,"pcol":0},
- "pcf002":{"wclosed":false,"wcollapsed":true,"pcol":1}
- },
- "posPortal":{
- "pos001":{"wclosed":false,"wcollapsed":true,"pcol":0},
- "pos002":{"wclosed":false,"wcollapsed":true,"pcol":1}
- }
- };
There can be more items in it than just "pcrPortal", "pcfPortal", and "posPortal".
How can I find out if a particular nested object exists in wDefaults? I have tried the following three methods, but I got "object is null or undefined" errors each time:
- var pID = "pcfPortal";
- if (wDefaults[pID].length) { /* it exists! */ }
- if (wDefaults[pID] != undefined) { /* it exists! */ }
- if (wDefaults[pID] != null) { /* it exists! */ }
Any help would be greatly appreciated!