简体   繁体   中英

Get JSON-Object Name as String in JavaScript

How do I get the object muxEnviroments as String? I want to analyze and compare to check what type of content I have to expect.

console.log(obj) shows me the whole object. My goal is something like that:

jsonObjectName = obj;
if(jsonObjectName =='muxEnviroments'){do the stuff...}

But how to get the Name 'muxEnviroments' as string?

{
    "muxEnviroments": [
        {
            "primaryTransmitterName": "sfu5",
            "primaryTransmitterIp": "10.7.50.1"
        },
        {
            "primaryTransmitterName": "sfu1",
            "primaryTransmitterIp": "10.7.50.4"
        }
    ]
}

您可以使用hasOwnProperty

if (obj.hasOwnProperty('muxEnviroments')) {do the stuff...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM