Use For in loop to display all properties in an object : for « Statement « Flash / Flex / ActionScript






Use For in loop to display all properties in an object

 
for (var element:String in targetObject) {
   // do some action
}

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var weather:Object = new Object();
        weather.temp = 45;
        weather.conditions = "rain";
        weather.pressure = 970;
        
        for (var element:String in weather) {
           trace(element + ": " + weather[element]);
        }

    }
  }
}

        








Related examples in the same category

1.The for Statement
2.Perform more complex initializations and increments by adding additional expressions separated by commas
3.Use a for loop to check whether a string contains the @ character
4.Place two statements in the for statement
5.Nested for loops
6.Use for each loop to go through the array elements
7.Use for loop to loop through the dynamic array
8.Use for statements to loop backward:
9.Use for loop statement to display all elements in an array
10.break is a keyword that allows you to stop processing a loop or conditional.