+ 1
Problem with var in loop [js]
hello :) I have a question. How can i solve this problem ? i would to do loop for variable. I don`t wanna writing all the time y1,y2,...y10. var y0 = 0; var y1 = 1 ; var y2 = 2; etc. it's some possibility to write something like this ? because ofc it`s not working. for(i=0;i<3;i++){ var y[i] = i; } I hope someone will help me. Greetings for all of you :)
2 Respuestas
+ 2
You probably want an array!
var y = [];
for(i = 0; i < 3; i++){
y[i] = i;
}
document.write(y[0]); // prints first element
+ 1
ya, thanks so much :):)