2

so i am working with a json variable like this:

opponentInvData.item1

it contains items 1 through 6

i need to access the different items dynamically and set them to null. itemNum is the specific item i need to access. im trying to use the eval function

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

needless to say, it's not working, any ideas?

1
  • You need to add quotations around opponentInvData.item in the eval call, otherwise it will use the current value. You shouldn't use this approach regardless - just saying what is wrong with your code. Commented Oct 4, 2010 at 23:13

1 Answer 1

6
opponentInvData['item1'] = "my item"

is the same as

opponentInvData.item1 = "my item"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.