I wonder if there is some way to use hasOwnProperty for an object for multiple levels.
To illustrate: I have following object:
var Client = {
ID: 1,
Details: {
Title: 'Dr',
Sex: 'male'
}
}
I can now do the following in javascript:
('Title' in Client.Details) -> true
However I cannot! do:
('Street' in Client.Adress)
...yet I must first use an if to not throw an error. Because I might have a large object - I only need to know if there is "Adress" in Client.Details without using prior if statements, any idea if that is possible?
// this is overkill -> (will be many more if-statements for checking a lower level
if('Adress' in Client){
console.log('Street' in Client.Adress)
} else {
console.log(false)
}
Example which produces the error:
var Client = {
ID: 1,
Details: {
Title: 'Dr',
Sex: 'male'
}
}
// Results in Error:
('Street' in Client.Adress)
// Results in Error:
if('Street' in Client.Adress){}