data = {}; $('section.tab-content').each((i, el) => { let section_data = []; let title = $(el).find('h2'); let h3s = $(el).find('h3'); let rows = $(el).find('.row-default'); console.log(title.text()); h3s.each((i, h3el) => { section_data.push({ header: $(h3el).text(), sections: [] }); }); rows.each((ri, rel) => { $(rel).find('.lg-3, .lg-4').each((si, sel) => { let s_data = { header: $(sel).find('h5').text(), links: [] }; $(sel).find('a').each((ai, a) => { s_data.links.push({ text: $(a).text(), url: a.pathname }) }); console.log(section_data[ri]); section_data[ri].sections.push(s_data); }); }); data[title.text()] = section_data; }); Object.keys(data).forEach(key => { console.log(key); console.log(JSON.stringify(data[key])); });