I'm getting an error of 'collection' undefined when trying to push object.
groupShortlists(lists: ProductShortlist[]) {
const grouped = lists.reduce((groupedList, list) => {
groupedList[list.collection] = [...groupedList[list.collection] || [], list];
return groupedList;
}, {});
return Object.keys(grouped).map(key => grouped[key]);
}
this.shortlistsCategory = [];
this.groupShortlists(this.shortLists).map((item, key) => {
this.shortlistsCategory.push({
collection: item[key].collection,
list: [],
});
});
The exact error says:
TypeError: Cannot read property 'collection' of undefined
Is this the proper way of using push. Any help would be appreciated. :D
index
. So make sure item[0] exists. – Yashwardhan PauranikgroupShortlists
do? Can you include a code snippet please – christianProductShortlist
? – christian