for...in

The for...in statement iterates over the enumerable properties of an object.

Syntax

<?ev
    for (variable in object) {
        statement
    }
?>

Where...

variable A different property name is assigned to variable on each iteration.
In Arrays or Collections this is usually the element index.
object Object whose enumerable properties are iterated.


Try it out

Let's say you want to iterate through a page's children:

<?ev
    for(var i in page.children){
        var childpage = page.children[i];
        echo(childpage.title.wrap('<h3 />'));
    }
?>

The code above iterates through page.children, which in this case is a collection of pages. The variable i is assigned the index property of the child page on each iteration. 

Difference between for...of and for...in

In EVML the for...in statement is designed to iterate across an objects properties rather than the values within the properties.

The following example highlights the difference between for...in and for...of

<?ev
    var myArray = ['One', 'Two', 'Three'];
    
    for(var i of myArray){
        print(i); // One, Two, Three
    }
    
    for(var i in myArray){
        print(i); // 0, 1, 2
    }
?>

See also for...of loops.