0

I have jquery object myObject like this(result of console.log())

Object { Product1 {...}, Product2 {...}, Product3 {...} }

and each of these products' pattern is like this Object { id="1", name="somename" }

I want to get the value of the name, when I change the radio button, e.g. if the first radio is checked I should get value of myObject.Product1, if second - myObject.Product2. When I e.g. try this console.log(myObject.Product1), it normally outputs Object { id="1", name="somename" }, but when I want to do it dynamically like

var number = getRadioValue(); // for example returns 1 
var productName = 'Product'+number;

then it outputs myObject.productName as undefined.

Thanks

1 Answer 1

3

If you are passing in a variable.. you should use the object[property] syntax instead of the . notation

myObject[productName]
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.