Joe Slater
Joe Slater

Reputation: 2473

How to use string to represent a variable

I have a object e which has properties like so e.property1, e.property2, e.property3 ...

Now I want to use a for loop to trace all the properties. How can I do that?

Something like this is what I am looking for -

for(var i:int =0; i<10; i++)
{
    trace(e.property+i); //how do I get the property no. i
}

Upvotes: 1

Views: 89

Answers (2)

M4tchB0X3r
M4tchB0X3r

Reputation: 1531

for (var i:* in e) trace(i+" :: "+e[i]);
// if they have to be strings just use ...+e[i].toString();

traces

property1 :: test
property2 :: 23.3
property3 :: 29

using fictional values here

Upvotes: 1

Vesper
Vesper

Reputation: 18747

for (var s:String in this) trace(this[s]);

Upvotes: 1

Related Questions