I am working with JSON data with multiple sets of key value pairs – each set constitutes a list. In the simplified example below, The list name is not known beforehand – actually I’ll need to populate a select dropdown on the page with the names of each list. How do I retrieve the set names in this situation?
({
"list1":
[{
"prodRating": "5",
"prodReviews": "21"
},
{
"prodRating": "5",
"prodReviews": "21"
}],
"list2":
[{
"prodRating": "5",
"prodReviews": "21"
},
{
"prodRating": "5",
"prodReviews": "21"
}]
})
Would display two alerts in this case saying “list1” and “list2”.
Here a little sample page which iterates over an object which is built like yours but the “labels” don’t have to be known.
And creates two selects dynamically
http://jsbin.com/azeha