JSFiddle - React, Tailwind, and code Playground
JavaScript
const productList = [{
productGroup : 'Namkeen',
index: 1,
items: [{
name: 'Haldiram',
item1: 'Bhujia',
item2: 'Aloo Bhujia'
},{
name: 'BiKaji',
item1: 'Bhujia',
item2: 'Aloo Bhujia'
},{
name: 'Bikaner',
item1: 'Bhujia',
item2: 'Aloo Bhujia'
}]
}, {
productGroup : 'Sweets',
index: 2,
items: [{
name: 'Haldiram',
item1: 'Chole Bhature',
item2: 'Barfi'
},{
name: 'Om sweets',
item1: 'Raj Kachori',
item2: 'Gazar Halwa'
}]
}];
const itemList = productList.map(obj => {
obj.items.map((itemObj, index) => {
itemObj.productGroup = obj.productGroup;
itemObj.pgIndex = obj.index;
itemObj.itemIndex = obj.index + '' + index;
});
return obj.items;
});
var mergedListItems = itemList.reduce((arr, arrNext) => arr.concat(arrNext));
console.log('mergedListItems', mergedListItems);