1

I'm trying to set different timestamps for each item in array, but I assume because the iteration happens so fast some items have the same timestamp (in milliseconds). Is there a way in pure JavaScript where I can get a timestamp down to the nanoseconds?

Is my assumption even correct?

Ioan Ungurean
  • 319
  • 1
  • 15
  • 3
    The closest you can get is `performance.now()` I think – Hao Wu Aug 03 '20 at 07:54
  • 1
    Why is it a problem that the timestamps overlap? If you need unique numbers only, then a simple incremental index can be used. If you need times, then normally it shouldn't matter that two things happened at the same time (according to the timestamp). If you do need to differentiate between things that happened the same millisecond, then perhaps you can add ordering, e.g., `1596441527494-1` and `1596441527494-2`. I'm not aware of a way to get guaranteed different timings in JS. – VLAZ Aug 03 '20 at 08:00

1 Answers1

-1

I would suggest to get current timestamp and then increase it manually in each iteration.

Den Kison
  • 1,074
  • 2
  • 13
  • 28