I had the idea to structure an object similar to this:
var collection = [{
'title': 'title1',
'content': {
'subtitle': 'sub1',
'contents': 'sub content 1'
}
}, {
'title': 'title2',
'content': {
'subtitle': 'sub2',
'contents': 'sub content 2'
}
}, {
'title': 'title3',
'content': {
'subtitle': 'sub1',
'contents': 'sub content 1'
}
}];
The array I am working with looks like this
var section = [];
for (var i = 0; i < data.length; ++i) {
section['title'] = data.title; //data.title represents title1 to title 3
for (var j = 0; j < data.sections.length; ++j) {
//data.sections[j].content represents {'subtitle':'sub1', 'contents':'sub content 1'}
}
}
I'm struggling to adjust my code to match the desired object structure. Can someone lend a hand? Much appreciated!