Message from JavaScript discussions

September 2020

— Ah good fixed

— 

Hi group!
I need help with a newbie doubt please. I need to assign one diferent variable name for each maped item but I'm having troubles with this.

— How can I fix my code to achieve this?

— For 2 items I expect an output like:
1
2

— You can use the eval(), but I don't recommend use it

— What do you want to do ?

— I neet to assign for each boxes item one diferent variable with a diferent value

— Oh I'm taking a look to eval option. Why not recomend this?

— 👍

— Thanks. Yes, it doesn't sound a good alternative 😕

— You can use objects

return ({
[`product:${i}`]: i,
});

— Actually the example was illustrative, but I need to assign something to the variable (a useRef () of react). Objects can't be an alternative here I think...

Message permanent page