0

I have a array with many UNIX timestamps and want for example get the timestamps, which are from the last e.g. 10 minutes.

To be more precise I only need the count, likely for a Bot protection.

Should I do it with a for loop and check if the UNIX timestamp + 600 is smaller than the current timestamp? Or is there a better way to do so?

Jannis Lehmann
  • 1,428
  • 3
  • 17
  • 31

1 Answers1

1

Use an Array filter, e.g

var now = Date.now();
var times = [now-10000, now-50, now-300, now-700, now];

var tenMinutesAgo = Date.now()-600;
var passed = times.filter(function(v){return v > tenMinutesAgo});

console.log(passed.length); // 3
Cuel
  • 2,620
  • 3
  • 13
  • 13