I have the following object called this.props
:
{
children: null,
location: {
action: 'POP',
query: {
seconds: '300'
}
}
}
After looking at this question I wrote the following code:
let seconds = 0;
console.log(this.props);
if('seconds' in this.props) {
seconds = parseInt(this.props.location.query.seconds, 10);
}
console.log(seconds);
In the console the object is logged as above, but seconds
is logged as 0.
I do not understand what is wrong with my if check, it seems that the condition is failing even though the nested object has the correct property (the issue is that when there is no query object, the whole this.props object is empty - so I need to check for nested properties).