I have an array as follows.
Array
(
[13] => Array
(
"eventName" => Array
(
[0] => 'Event Name1'
[1] => 'Event Name2'
)
"eventInfo" => Array
(
[0] => 'Event Information1'
[1] => 'Event Information2'
)
)
[20] => Array
(
"eventName" => 'Event Name1'
"eventInfo" => 'Event Information1'
)
)
I will be using this data to push information into a calendar; the first level of the array represents the date. I send the content as a json string to javascript and then parse. Once the content is an object, how do I determine if the value of key "eventName" is a string or array. So for I have
var object = JSON.parse(data);
var objectSize = Object.keys(object).length;
for(var i = 0; i < objectSize; i++){
var id = Object.keys(object)[i];
if(Object.keys(object[id].eventName) != string){ //How do I fix this line?
var arraySize = Object.keys(object[id].eventName).length;
for(var r = 0; r < arraySize; r++){
//update calendar cell
}
} else {
//update calendar cell
}
}
How do I fix this line?
if(Object.keys(object[id].eventName) != string){
I tried this with no luck.
if(Array.isArray(Object.keys(object[id].eventName))){
typeof object[id].eventName !== 'string'?