amt: \"10.00\"
email: \"sam@gmail.com\"
merchant_id: \"sam\"
mobileNo: \"9874563210\"
orderID: \"123456\"
passkey: \"1234\"
The above is the JSON o
Try this,
if(thisSession.hasOwnProperty('merchant_id')){
}
the JS Object thisSession
should be like
{
amt: "10.00",
email: "sam@gmail.com",
merchant_id: "sam",
mobileNo: "9874563210",
orderID: "123456",
passkey: "1234"
}
you can find the details here
You can try if(typeof object !== 'undefined')
I change your if statement slightly and works (also for inherited obj - look on snippet)
if(!("merchant_id" in thisSession)) alert("yeah");
var sessionA = {
amt: "10.00",
email: "sam@gmail.com",
merchant_id: "sam",
mobileNo: "9874563210",
orderID: "123456",
passkey: "1234",
}
var sessionB = {
amt: "10.00",
email: "sam@gmail.com",
mobileNo: "9874563210",
orderID: "123456",
passkey: "1234",
}
var sessionCfromA = Object.create(sessionA); // inheritance
sessionCfromA.name = 'john';
if (!("merchant_id" in sessionA)) alert("merchant_id not in sessionA");
if (!("merchant_id" in sessionB)) alert("merchant_id not in sessionB");
if (!("merchant_id" in sessionCfromA)) alert("merchant_id not in sessionCfromA");
if ("merchant_id" in sessionA) alert("merchant_id in sessionA");
if ("merchant_id" in sessionB) alert("merchant_id in sessionB");
if ("merchant_id" in sessionCfromA) alert("merchant_id in sessionCfromA");