How to use a variable in a variable name

so i work with json variable like this:

opponentInvData.item1

contains items 1 to 6

I need to dynamically access various elements and set them to null. itemNum is the specific item I need. im trying to use eval function

var itemNum = 2;
eval(opponentInvData.item + itemNum + ' = ""');

Of course, it does not work, any ideas?

+2
source share
1 answer
opponentInvData['item1'] = "my item"

coincides with

opponentInvData.item1 = "my item"
+6
source

All Articles