0

I created some vars inside vars, then i made a loop to go var per var, the thing is i can't acces the inside variables, sorry if i didn't explain well, here's my code:

var Variable1 = {
        Name: "Variable1",
        Age: 25,
        Brothers: 2
    };

    var Variable2= {
        Name: "Variable2",
        Age: 10,
        Brothers: 3
    };

    /******************************************************* */

    var TotalVariables= 2;

    /******************************************************* */
    
    for(var i = 1; i <= TotalVariables; i++) {
        console.log(("Variable" + i).Age);
    }
WebDev001
  • 61
  • 5
  • 1
    That's what arrays are for: `let variables = [ { name: "Variable1", age: 25 }, { name: "Variable2", age: 10 } ]`, `console.log( variables[0] )`, `console.log( variables[1] )`. – Dai Aug 08 '21 at 06:13

0 Answers0