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

Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
celsowm
  • 556
  • 8
  • 30
  • 54

2 Answers2

6
var i;
for (i = 1; i < 5; ++i) {
    alert(obj['resposta' + i]);
}
Chris Jester-Young
  • 213,251
  • 44
  • 377
  • 423
1

Try this:

for ( var int = 1; int < 5; int++){
    obj['resposta'+int];
}
Shef
  • 43,457
  • 15
  • 77
  • 89
  • `int` isn't exactly a good choice of variable name, since it's easily confused with other languages where it's a keyword. – Neil Jun 16 '11 at 23:00
  • @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. – Shef Jun 16 '11 at 23:07