You don’t want this. Do all of your processing and displaying from within getJSON’s callback. You can write a function somewhere else and call it there if you want, but don’t count on manipulating variables outside of your function’s scope.
You’re going to get the same number, and it will be streamer.length. The easiest way to fix this is to use let instead of var in your loop. If you haven’t learned about this yet, don’t worry. let means JavaScript will create a new variable for each loop. var reuses the same variable, which gets overwritten.
for(let i = 0; i < streamer.length; i++) {
// do stuff
}
It works, I’ve not fully understood what you said about let, but it works! I need to get more informations with this, thank you for your very fast answer ! you’re Supercodeman !
Just one last thing, according to your first answer, if I have a table variable, in this example it’s
horsLigne is not modified and you said me that I must not use variable out of scope, that mean it’s not good to do this ? I juste want to have a table of names, passing it in a function which determine if players are online and returning me a table with only notOnline names, like a new variable I can access out of notOnline().
Yes, don’t do this. It may seem like an easy way to keep track of the results, but when you’re working with AJAX requests like getJSON, things don’t always happen when you expect them to. We already saw this with the for loop - h was not the value you thought it would be because of the way JavaScript handles asynchronous requests.