# Iterations functions

# For each

You can iterate over a list using the built-in each helper. Inside the block, you can use this to reference the element being iterated over. contextualListVariable is an iterable item on which the mydata property is displayed for all entries.

The @index is a special variable available in the each loop context which value is the current index of the element being iterated. There are agic* variables like @index in a each context. The following ones are also available: @key @index @first @last @odd @even

See handlebars documentation for more about this topic.

{{#each contextualListVariable}}
    {{this.mydata}} {{@index}}

will produce

one 0
two 1
three 2
django! 3

for the following data sample when

contextualListVariable = [
  {"mydata": "one"},
  {"mydata": "two"},
  {"mydata": "three"},
  {"mydata": "django!"},

If the contextual 'this' is not convenient to use the data as you wish, it is possible to alias it as shown below:

{{#each iterableVariable as | myItem | }}