Skip to main content
Inspiring
May 21, 2020
Answered

Probleme mit Klammern

  • May 21, 2020
  • 1 reply
  • 777 views

hallo, was fuer klammern muss ich setzen ??

{gehe.menue_land_[i].visible = false;}

 

danke vorab

for (var i = 1; i <= 2; i++) {

		if (i == 1) {

			{gehe.menue_land_1.visible = true;}

		} else
		{gehe.menue_land_[i].visible = false;}

		}

 ( 

    This topic has been closed for replies.
    Correct answer hds26846

    Danke !!!!

    Funktioniert !!!

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 21, 2020

    Hi.

     

    To use bracket notation, put the fixed part of the name between quotes then add the variable part using the + operator. Like this:

    for (var i = 1; i <= 2; i++)
    {
    	if (i == 1)
    	{
    		gehe["menue_land_" + i].visible = true;
    	}
    	else
    	{
    		gehe["menue_land_" + i].visible = false;
    	}
    }

     

    Also, you have unneeded extra curly braces here:

    {gehe.menue_land_1.visible = true;}

     

    And as a bonus, your whole code could be written like this:

    for (var i = 1; i <= 2; i++)
    	gehe["menue_land_" + i].visible = i == 1;

     

    Please let us know if you have any further questions.

     

    Regards,

    JC

    hds26846AuthorCorrect answer
    Inspiring
    May 21, 2020

    Danke !!!!

    Funktioniert !!!

    JoãoCésar17023019
    Community Expert
    Community Expert
    May 21, 2020

    Excellent!

     

    You're welcome!