How to change value in After Effects when passing marker
marker.nearestKey picks the closest marker - even if it is in the future.  

A simple solution would be to iterate over the markers with a for loop instead:

if (marker.numKeys &gt; 0) {
    let i;
    for (i = 0; i &lt; marker.numKeys; i++) { // For every marker we have, add 1 to i
        if (marker.key(i+1).time &gt; time)   // If the marker is past current time,
            break;                         // stop the loop
    }
    i; // Return i value
}