Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Id for setInterval. How does it work?

Tags:

javascript

Suppose I have an array that stores all my ids used for setInterval.

What if I want to create an id, dynamically... can I do like this?

id_array.push(++id_var) = setInterval(function, milliseconds);

See?

I also have a variable, called 'id_var', that I believe, if I increment it, it will give me, a new 'id'.

Is this code correct?

like image 501
Marcelo Noronha Avatar asked Jul 01 '26 02:07

Marcelo Noronha


1 Answers

The return value from setInterval() is an opaque token. You just store it somewhere until you want to remove the interval timer with clearInterval().

You cannot control the value of what you receive, nor can you do any kind of arithmetic on it. Just store it and retrieve it.

like image 132
Francis Avila Avatar answered Jul 03 '26 15:07

Francis Avila