I have the following:
<code>const categorizedDatas2 = maam.reduce((acc, curr) => {
const { id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status } = curr;
const categorymatch = Object.values(newata?.GearCategories).filter(chunk => chunk.id === CategoryId)
const realcat = categorymatch[0].label
if (!acc[Owner]) {
acc[Owner] = {
items: [],
};
}
acc[Owner].items.push({ id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status });
return acc;
}, {});
</code>
<code>const categorizedDatas2 = maam.reduce((acc, curr) => {
const { id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status } = curr;
const categorymatch = Object.values(newata?.GearCategories).filter(chunk => chunk.id === CategoryId)
const realcat = categorymatch[0].label
if (!acc[Owner]) {
acc[Owner] = {
items: [],
};
}
acc[Owner].items.push({ id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status });
return acc;
}, {});
</code>
const categorizedDatas2 = maam.reduce((acc, curr) => {
const { id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status } = curr;
const categorymatch = Object.values(newata?.GearCategories).filter(chunk => chunk.id === CategoryId)
const realcat = categorymatch[0].label
if (!acc[Owner]) {
acc[Owner] = {
items: [],
};
}
acc[Owner].items.push({ id, Category, CategoryId, SubCategory, SubCategoryId, Name, Brand, Owner, RealOwner, packingLocation, Quantity, Weight, Status });
return acc;
}, {});
categorymatch is returning the error:
Cannot convert undefined or null to object
console.log of newata?.GearCategories gives me several undefined but am not sure how to skip or ignore these?