{
"@": {
"xmlns": "http://ses.amazonaws.com/doc/2010-12-01/"
},
"SendEmailResult": {
"MessageId": "0000012fdd10caaf-021c6e9e-e872-4b35-ad94-1d11c79a6324-000000"
},
"ResponseMetadata": {
"RequestId": "736d5bb2-7b7d-11e0-b435-f7b0c9315f0d"
}
}
How do I check if “MessageId” exists in a object? (without throwing errors)
I might get other json objects returned, and I need to know if the one I get has a “MessageId”.
Assuming you have a reference to it in
obj, then:Probably more usefully, though:
JavaScript’s AND operator
&&is more useful than that of some other languages, it returns the right-hand side’s value if both of its operands are “truthy” (rather than just returning atrue/falseresult, as in most languages). A “truthy” value is a value that is not “falsy” (obviously). “Falsy” values arefalse,undefined,null,"", and0.So the above basically says “Set
msgidtoobj.SendEmailResult.MessageIdprovided thatobjandobj.SomeEmailResultboth exist.(The
||operator is similarly powerful.)