Storing an index by a counter

Might I suggest yu read the documentation about context - It may give you some ideas
https://nodered.org/docs/user-guide/context and this thread might help