I have a nested array as below. I am trying to first loop the top level array and get the groupValue and then for every group value I need to loop over the docs array and get the title for each document.
Nested array example:
[ { groupValue: 'Heading1',
doclist: { numFound: 958, start: 0, maxScore: 1.2041028, docs: [Object] } },
{ groupValue: 'Heading2',
doclist: { numFound: 8700, start: 0, maxScore: 0.50214005, docs: [Object] } },
{ groupValue: 'Heading3',
doclist: { numFound: 1138, start: 0, maxScore: 0.48008662, docs: [Object] } } ]
Expected Output:
Heading1:
iphone
samsung
Heading2:
motorola
ipad
I tried the below approach and I was able to return all child elements but I am not sure how to return the heading from the parent array along with the corresponding child elements.
var values=groups.map(function(item,i) {
let docs=groups[i].doclist.docs
console.log(groups[i].groupValue);
return docs.map(function(item,i) {
return (<div key={i}>{docs[i].title}</div>);
})
});