1

In my object

obj.resposta1
obj.resposta2
obj.resposta3
obj.resposta4

how access the values of each inside a

for ( var int = 1; int < 5; int++)

?

Thanks, Celso

2

2 Answers 2

6
var i;
for (i = 1; i < 5; ++i) {
    alert(obj['resposta' + i]);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

for ( var int = 1; int < 5; int++){
    obj['resposta'+int];
}

2 Comments

int isn't exactly a good choice of variable name, since it's easily confused with other languages where it's a keyword.
@Neil: Totally agree! Just gave an answer based on the given code. I didn't validate the code, neither did I show an example of what to do with the object, once it has been accessed, just showed the way to access it.

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.