I have a json file with the following object:
{
"month": "April",
"events" : [
"event 1",
"event 2"
] ,
"event 1": [
"1.3",
"2.3",
"3.3",
"4.3"
],
"event 2": [
"7.3",
"16.3"
]
}
I’d like to get the key of the Object for further transactions.
let datesOfEvents = [];
var jSObject = getData().then((a) =>{
for (let i = 0; i<a.length;i++){
if(typeof a[i].events !== 'undefined'){
for (let key in a[i] ){
if (key == "event1"){
datesOfEvents = a[i].key;
}
}
}
}
})
As the key value, I’m asking for in the if statement is a String, I cannot call the other values this way a[i].key
. when I call them individually, like this:
datesOfEvents = a[i].event1;
it works fine. My question is: what type do I have to query in the if statement to get the values of event1?