I'm working with an API call that's returning JSON and in some scenarios some of the data is empty. For example, the snippet below shows that roleBusinessScopes is empty.
{
"userProfile": {
"organizationContacts": [
{
"roleBusinessScopes": {}
}
]
}
}
I wanted to be able to check if roleBusinessScopes is empty. I tried roleBusinessScopes.length = 0, however, that doesn't work.
When roleBusinessScopes does return data...
"roleBusinessScopes": {
"businessScopes": {
"scopeName": "something"
}
}
... I can check for that:
if (organizationContacts[i].roleBusinessScopes.businessScopes[0].scopeName !== "something")
{
// do something
}
How can I check if roleBusinessScopes has no data?
if (roleBusinessScopes.length = 0)? so you miss=there. check it withif (roleBusinessScopes.length == 0)orif (roleBusinessScopes.length > 0)