When solving the access to a JSON through forEach ( Is it possible to access the following JSON? ).
The following doubts arose:
How can I access each "each" to pass if/else conditions to it?
Namely:
var response = json; // json file or response
response.data.forEach(function(key, value){
console.log("Nombre: "+key["username"]+".");
// response: Nombre: Juan. Nombre: Luis. Nombre: Micaela.
})
I want to try to do something like:
if(key["username"]==="Juan"){
console.log(key["username"])
// Nececito que sea: Juan. Y no todos los nombres.
}else{
console.log("No username");
}
Now, the JSON/Object (comes from the Twitch Api Helix). If the "streamer" is live, twitch sends an object with data. If the "streamer" is offline, twitch does not send any object.
That is: (api call for 3 users - 2 on - 1 off)
let datos = {"data":
[{
"id":"user_id",
"login":"user_login",
"display_name":"user_ds",
"type":"","broadcaster_type":"partner",
"description":"user_desc",
"profile_image_url":"url",
"offline_image_url":"url",
"view_count":123
},
{
"id":"user_id",
"login":"user_login",
"display_name":"user_ds",
"type":"","broadcaster_type":"partner",
"description":"user_desc",
"profile_image_url":"url",
"offline_image_url":"url",
"view_count":123
}
]
}
Is there the possibility of obtaining that data according to the (key,value) ?