0
I have a loop inside a request, which adds an ID in an array, so that on the next repeat it checks if this same ID is no longer added. and if it is already in the array, skip to the next array id.
setInterval(all, 5000);
function all{
request(html[i], function(erro,resp,html)
{
var data = JSON.parse(html[i]);
if(all_id[index] != data.live_id)
{
all_id.push(data.live_id)
index++
}else{
index++
}
}
}
But for some reason, my loop is not doing what I want, and ends up adding the same values making my ID check not work, as I can solve?
In the image of to see the loop adding again the same values but backward.
Why don’t you search first of then enter if there is no Ex.:
if( all_id.findIndex(data.live_id) == -1 ) all_id.push(data.live_id)
– adventistaam
It worked out! Thank you.
– Vinicíus
I’m glad it worked out!
– adventistaam