Often times, I have to check an object's deeply nested boolean value to see whether it exists and if so, whether it is true
or false
.
Let's say, I want to check if payload.options.save
is set to false
, but I do not know if document
and options
even exist in the payload
object.
Currently, I do that:
if (payload && payload.document && payload.document.options && payload.document.options.save && payload.document.options.save === false) {
resolve(payload);
return;
}
Is there a shorter way to check that?
Aucun commentaire:
Enregistrer un commentaire