Check if a key exists inside a json object

后端 未结 9 1382
旧巷少年郎
旧巷少年郎 2020-11-29 14:48
amt: \"10.00\"
email: \"sam@gmail.com\"
merchant_id: \"sam\"
mobileNo: \"9874563210\"
orderID: \"123456\"
passkey: \"1234\"

The above is the JSON o

9条回答
  •  庸人自扰
    2020-11-29 15:41

    you can do like this:

    if("merchant_id" in thisSession){ /** will return true if exist */
     console.log('Exist!');
    }
    

    or

    if(thisSession["merchant_id"]){ /** will return its value if exist */
     console.log('Exist!');
    }
    

提交回复
热议问题