0

I have:

Main.children.firstfunction.isEnabled = true;
Main.children.second.isEnabled = true;
Main.children.gsdfgsg.isEnabled = true;
Main.children.other.isEnabled = true;

All of these is working good, but such calls is a lot of, so I have in array:

var names = ['firstfunction', 'second', 'gsdfgsg', 'other'];

And I would like do:

for (var name in names) {
    Main.children.name.isEnabled = true;
}

But of course it does not work. How can I improve it?

zege
  • 3
  • 1

1 Answers1

1

Use bracket ([]) notation. This will allow you to evaluate the property names dynamically.

Try

for (var name in names) {
   Main.children[name].isEnabled = true;
}
Mamun
  • 66,969
  • 9
  • 47
  • 59