I am mapping out an array in one of my React components.
Is it possible to replace values when using map to write out each member of an array?
For example, if I have this array:
{ rowInfo.value.map(
weaponIds => (<span>{weaponIds}</span>)
) }
that writes out:
<span> 1 </span>
<span> 3 </span>
<span> 4 </span>
<span> 8 </span>
Can I change it so that, instead of printing out the Id, it prints out the name of the weapon associated with that ID?
so :
<span> Pistol </span>
<span> Hunting Rifle </span>
<span> Machete </span>
<span> Machine Gun </span>
Note that the names do not exist in the API.
So I would somehow have to assign it so that 1 = Pistol, 2 = Dagger, 3 = Hunting Rifle, etc...
I tried writing out like this:
{ rowInfo.value.map(
weaponIds => (<span>{weaponIds => (1 = Pistol), (2 = Dagger) etc... }</span>)
) }
But that throws a bunch of errors and my page no longer loads at all.
Thanks for any helps! :)
weaponIds => ({1: 'Pistol', 2: 'Dagger', ...}[weaponIds])or something of that natureconst weapons = {1: 'Pistol', 2: 'Dagger'};and use this asweapons[weaponIds]