I am having the JSON array of objects like below,
let data = [
{
"node":[
{
"name":"aaaaa",
"count":"2",
}
]
},
{
"client":[
{
"name":"bbbbb",
"count":"2",
}
]
},
{
"ip_address":[
{
"name":"ccccc",
"count":"3",
}
]
},
{
"compute":[
{
"name":"dddd",
"count":"1",
}
]
}
]
let find_key = "ip_address";
Need to check whether the root key is exists or not(for example need to find ip_address
is exists or not). without foreach please.
JSFiddle Link : https://jsfiddle.net/b9gxhnko/
Tried the following ways but no luck. Some help would be appreciated. Thanks in advance.
Tried like below, but its not working (always returning false
),
console.log(data[0].has(find_key)); // false
console.log(data.has(find_key)); // false
console.log(data[0].hasOwnProperty(find_key)); // false