I have an object (categorizedDatas2) like so:
{
"Mike": {
"items": [
{
"id": "EQLwvDPfgLyXk5c7Bbr0",
"Category": "01. SAFETY",
"CategoryId": "default-090",
"SubCategory": "PLBS & EPIRBS",
"SubCategoryId": "default-093",
"Name": "T610G PLB",
"Brand": "GME",
"Owner": "Bob",
"RealOwner": "Bob",
"packingLocation": "To Pack",
"Quantity": 1,
"Weight": 0.16,
"Status": "Ready"
},
{
"id": "90952450-0c6b-11ec-90f3-ff0167255365",
"Category": "05. HIKE",
"CategoryId": "default-050",
"SubCategory": "POLES",
"SubCategoryId": "default-054",
"Name": "Carbon Z Poles - Large",
"Brand": "BLACK DIAMOND",
"Owner": "Dave",
"RealOwner": "Dave",
"packingLocation": "Wear",
"Quantity": 1,
"Weight": 0.3,
"Status": "Ready"
}
]
}
}
The Category name attached to each item has been changed – so it stores the CategoryId of the original item so we can look it up to get the changed name.
These details are held in a different array (newata), and I am using:
const getCategoryPackedAlt = (key) => {
const foundCategorykey = categorizedDatas2[key].items[0].CategoryId
const foundCategory = newata?.GearCategories?.find((element) => element.id == foundCategorykey)
if (foundCategory) {
return foundCategory.label
} else {
return '-'
}
}
This works but it only returns the first item Category name and shows for all items.
In my map I use:
{getCategoryPackedAlt(key)}
How can I loop through each item in categorizedDatas2 and show the correct Category name?