This question already has an answer here:
- Check if object is array? [duplicate] 22 answers
i got a dynamic json object that can contain different type of attributes and objects inside, could have plane strings or even arrays. I made a javascript code to convert a single json structure to an HTML table, worked great but id like to make it for a dynamic json, so basically i would need to iterate through the json tree parents and childs to see how do i create this HTML table.
But i do have some problems when trying to validate if a child has an object inside, like this: ( i dont want to add to many details to the json)
parent: {
child_1: {
attr1 : value1
},
child_2: {
[{ attribues and values in an array }]
}
}
How could i achieve this? I was thinking of using the "typeof" function like so:
if (typeof key === 'array') {
// do something
}else{
// do another stuff
}
But i don't believe it would work well, can you guys help me?
Thanks in advance.
typeof key
will return "object" for arrays, thustypeof key === 'array'
will always be false – Vadim May 6 '13 at 19:43