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
  • 795,719
  • 175
  • 1,089
  • 1,143
celsowm
  • 846
  • 9
  • 34
  • 59

2 Answers2

6
var i;
for (i = 1; i < 5; ++i) {
    alert(obj['resposta' + i]);
}
C. K. Young
  • 219,335
  • 46
  • 382
  • 435
1

Try this:

for ( var int = 1; int < 5; int++){
    obj['resposta'+int];
}
Shef
  • 44,808
  • 15
  • 79
  • 90
  • `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