Say you have a large object, picture it coming from typical json/api, and you have something like ..
tell( bigObj.payload.docs[i][name].length ) // prints 19,307
of course, the docs
array may not exist (perhaps it was missing in the data from the endpoint)
So superficially to avoid a crash you
if (bigObj.payload.docs === undefined) {
log .. docs array missing !!
}
else {
tell( bigObj.payload.docs[i][name].length ) // prints 2,704
}
However that’s actually wrong. You have to go through them one at a time …
if (bigObj.payload === undefined || bigObj.payload.docs === undefined) {
log .. docs array missing !!
}
It’s a total pain if you’re 3 or 4 deep!
In short, node experts,
is there any way, or indeed a better way? TY