The Expressions Cheat Sheet
Loading...

"index" gives as an index of a layer. In this case, the layer the expression belongs to.

thisLayer.index

Every layer has a number, usually stated to the left of the layer's name. The further down the comp a layer is, the bigger its index.

Rotate by index

Let's tell the layer to rotate based on its index. We're gonna multiply the index by however many degrees we want to spin each layer. Let's use 36 degrees for now, like so:

thisLayer.index * 36

Now select and layer duplicate it (Cmd + D \ Ctrl + D) a bunch of times and behold:

How cool is that?

Why did we use 36 degrees?

In order to finish one rotation lap, we need 360 degrees. Multiplying 36 by the layer index will get us to 360 by the 10th layer.
You can use however many degrees you want.

Using a slider.

Let's do the exact same thing, but instead of hard coding a number of degrees, we're gonna use a slider to set it later on.
We're going to create a new null (Layer -> New -> Null Object) and add a slider to it (Effect->Expression Controls -> Slider Control).

Now we can duplicate our layer a bunch of times. You might notice that nothing seems to happen, but that's okay.
That's probably because your slider's value is set to 0, which results in all rotations being 0.
Play around with the slider and behold:

This method is cool, however, it can be unreliable at times, as the index of the layer can change as you design your comp.
You rarely think about the index of a layer in any meaningful way when working with After-Effects, because reordering layers in the timeline dictates the order in which layers are stacked upon each other.
You can try messing this constellation up by creating a new layer that does not have this expression already, and move it up and down in the timeline.
See how some copies disappear?

Also, if you want to make a change to this expression you would have to do this 9 times, or at least once, and then copy it over to all the other layers.
Programming wise these are not good habits, but within the After-Effects environment sometimes there is no choice but to use a layer's index in an expression.

The layer index is great! Just...messy at times.