Map cat ids of prod object with cat name string value from cat object. I want to display prod in HTML with string cat.
var prod = [
{ name: "Necklace", cat: [1, 2, 3] },
{ name: "Bindi", cat: [2, 4] }
]
var cat = [
{ id: 1, name: "gold" },
{ id: 2, name: "silver" },
{ id: 3, name: "platinum" },
{ id: 4, name: "copper" }
]
prod.forEach((p) => {
p.cat.forEach((c) => {
cat.filter((d) => {
if (c == d.id) {
//logic to display cat of prod in string
}
})
})
})
HTML:
<ul class="flex-container">
<li *ngFor="let product of prod">
<label>Name-{{product.name}}</label><br>
<label>cat-{{product.cat}}</label>
</li>
</ul>
Actual output:
Name-Necklace
cat-[1,2,3]
Name-Bindi
cat-[2,4]
Expected output:
Name-Necklace
cat-gold,silver,platinum
Name-Bindi
cat-silver,copper