function groupBy(array, f,hasKey) { debugger; const groups = {}; array.forEach(function (o) { const group = hasKey?f(o):JSON.stringify(f(o)); groups[group] = groups[group] || []; groups[group].push(o); }); if(hasKey)return groups; return Object.keys(groups).map(function (group) { return groups[group]; }); } c=groupBy(PRODUCTS,(item)=>(item[‘category‘]),true)