+ 2
Can I create variable using for loop?
Suppose, I have a word "hello". Now, can I create variable as hello1, hello2, hello3... using a for loop?
6 Answers
+ 4
Well using array variables is kinda like that: e.g. hello[1], hello[2], hello[3] etc.
+ 4
Name
You cannot create variable but you can create key for an object.
var a = new Object ();
for(var i = 1; i <= 3; i++) {
a['word' + i] = i;
}
console.log(a.word1);
console.log(a.word2);
console.log(a.word3);
+ 2
Something like that?
https://www.sololearn.com/discuss/2666047/?ref=app
+ 2
Name I don't know much Java.
Also I don't know what kind of task you are trying to accomplish but generally it is not advisable to create variables at runtime like this (I expressed this worry in the linked thread).
+ 1
Lisa, I got it thanks... đ... Can you suggest for java?
+ 1
Name console.log() is javascript