Check if a key exists inside a json object

后端 未结 9 1373
旧巷少年郎
旧巷少年郎 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:34

    (I wanted to point this out even though I'm late to the party)
    The original question you were trying to find a 'Not IN' essentially. It looks like is not supported from the research (2 links below) that I was doing.

    So if you wanted to do a 'Not In':

    ("merchant_id" in x)
    true
    ("merchant_id_NotInObject" in x)
    false 
    

    I'd recommend just setting that expression == to what you're looking for

    if (("merchant_id" in thisSession)==false)
    {
        // do nothing.
    }
    else 
    {
        alert("yeah");
    }
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in http://www.w3schools.com/jsref/jsref_operators.asp

提交回复
热议问题