-1

why does this

http://jsfiddle.net/BkGxq/1/

return "$undefined" ?

if i dont do

 level_prices['f'.i] = i;

and do

 level_prices[i] = i;

it works, (i also change it in the html to value="3" rather then value="f3"

but i need to access it as f3 and not 3, why does it not work?

0

2 Answers 2

2

The dot is not the string concatenation operator, but the property accessor. You want

level_prices['f'+i] = i;

'f'.i gets the literal "i" property of the string object, which is undefined.

Sign up to request clarification or add additional context in comments.

Comments

0

In JavaScript, you concatenate strings with + instead of .

Try:

level_prices['f'+i] = i;

Edit: updated your JSFiddle: http://jsfiddle.net/BkGxq/2/

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.