0
 var my_obj = {};
 var my_array = [];   

var j= "10";
  var k = "5";
  var subject = "10";
  var klass = "Math";

for (i= 1; i< j; i++) {
for (k = 0; c < k; k++) {   
   if (k== 1) {
    var first = "hello" + row;
     }
    if (k== 2) {
     var second = subject + k;  //var hello1 =  subject + k; -- I would like to have "hello1" which is here the first variable value!
     }
    if (k==3) {
    var hello2 = klass + k;
  }
  }
 my_obj = { first : first, second:second; third:third}; } 
  }
  my_array.push(my_obj);

I would like to represent the name of second variable as variable first's value. For example, I need to call variable name as hello1 and hello2. How to achieve this?

user3280899
  • 199
  • 2
  • 13
  • You should be using an array or an object. Any time you are trying to dynamically concoct variable names it's a clue that you should be using a different data structure. But since your code isn't actually doing anything with these variables, it's hard to know what to suggest. – Mark Jan 19 '19 at 19:03
  • please do not use `class` as variable name, it is a reserved word for declaring a class. btw, you need numbers instead of strings for a counting for loop and you have no `c` declared. – Nina Scholz Jan 19 '19 at 19:08
  • @Mark : I entered only pseudo code. My code is very complex, not possible to use it here. The question is How I can use the result of the "first" variable as a name of next (second) variable? – user3280899 Jan 19 '19 at 19:16
  • @Nina : This is not a "real" code... anyhow I changed it to klass :-) – user3280899 Jan 19 '19 at 19:16
  • @user3280899 if your code is very complex it's even more important that you use real data structures like an array. Then you have `hello = []` and `hello[1]`, `hello[2]`, etc. – Mark Jan 19 '19 at 19:39

0 Answers0