If you measured the
time in ms from the start of the animation, the formula would be:
var frame_nr = Math.floor(FPS * time / 1000);
This way if your
time was say 500 [ms] and your
FPS was 60, the
frame_nr would be 30.
You'd need to handle the case when the
frame_nr exceeds your animation's length.
If you wanted the animation to loop, you could use the modulo operator:
var frame_nr = Math.floor(FPS * time / 1000) % frames.length;
So at half a second and 60 FPS and 30 frames long animation, the
frame_nr would wrap back to 0.
Otherwise, if the animation was to be played just once, before you used a
frames_nr to refer to an actual frame, you'd have to test for:
if (frame_nr < frames.length)
... // animation ended
Finally, to measure
time you'd have to initialize the variable to 0 when your animation starts, and then at each frame accumulate the delta you already have available.