Increment a number, based on number of keyframes in After Effects?
Yep, just do



var p = &lt;pick whip the property with the keyframes here&gt;;
var k = p.nearestKey(time);
if (k.time &lt;= time){
    k.index; //key is in the past
} else {
    k.index-1; //nearest key is in the future, return the previous key
}


On the first line you have to reference the property with the keyframes. The easiest way is with the pick whip (the curly thing in the expressions buttons). Drag it to the property you want to reference.



So the first line should look something like this:

var p = thisComp.layer("Pale Gray-Magenta Solid 2").effect("Slider Control")("Slider");


or

var p = transform.position;


Don't forget the semi-colon at the end.