I need an array of alt strings. I can map the array with name strings, but can't get it to return the "alt". This is what I tried:
const data = [
{ name: "Apple", alt: "Fruit" },
{ name: "Banana", alt: "Fruit" },
{ name: "Potatoe", alt: "Vegetable" },
{ name: "Lentil", alt: "Legume" }];
<span>
{data.map(item => {
return (
<Button item={item.alt.toUpperCase()}>
{item}
</Button>
);
})}
</span>
To get an array of namestrings, this worked:
<span>
{data.map(item => {
return (
<Button key={item.name} item={item.name.toUpperCase()}>
{item}
</Button>
);
})}
</span>
This is the error: TypeError: Cannot read property 'toUpperCase' of undefined
{item}inside button, which is an object. Either return{item.name}or{item.alt}item.altseems undefined in some places