Just wanted to ask what is best practise for running multiple javascript checks on a returned object from a api.
For instance if the api returns this json.
var ob = {
"destination_addresses" : [ "15 Duke St, Cardiff, Cardiff CF10, UK" ],
"origin_addresses" : [ "2 College St, Swansea, Swansea SA1 5AE, UK" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "67.9 km",
"value" : 67941
},
"duration" : {
"text" : "57 mins",
"value" : 3446
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
So say i want check if duration exists only but i don't want to do the following.
if(ob.rows){
if(ob.rows[0].elements){
if(ob.rows[0].elements[0].duration.text != undefined ){
console.log(ob.rows[0].elements[0].duration.text);
}
}
}
Is there a better way to just check in duration and text exists?