I don't normally have a problem with looping through objects and arrays with jQuery but this has got me stumped.
I have an order list which I need to add list items to using the object. I'm trying to loop through the object and create a list item for each of the keys and inside of that list item, I need to create another ordered list with the values from the array.
I can get the outer list items working okay but when it comes to the nested lists, it all goes pear shaped.
var obj = {
2: ['a','b','c','d','e'],
3: ['a','b','c','d','e'],
4: ['a','b','c','d','e'],
5: ['a','b','c','d','e'],
};
$.each(obj, function(key, val) {
// create the parent list items
$('.list').append($('<li></li>').html('<a href="#">Row ' + key + '</a><ol></ol>'));
// create the nested list items
$.each(val, function(k, v) {
// this is where it goes wrong
});
});
I have searched SO for a solution and elsewhere but can't find anything that works for me