Trying to use "ForEach"

Hi, people!

I'm trying to change some events in my map to use Stepping.
By default, all of them are with the Stepping box unchecked.
But something happens, then a lot of them have to change to Stepping animation.
Well, I manage to use the script call to all of them in this way(using move route script field):

Code:
$gameMap.event(2).setStepAnime(true);
$gameMap.event(3).setStepAnime(true);
$gameMap.event(4).setStepAnime(true);
etc...

But, how can I make this more simple?
I'm trying to use "ForEach" to englobe all events.
I try to put the id of the events in a variable:
var casa = [2, 3, 4, 5]
$gameMap.event(casa).setStepAnime(true);

or
var casa = [2, 3, 4, 5]
$gameMap.event((forEach(casa))).setStepAnime(true);

But I can't get it to work 🙁

I already try to use the sentence "for (var i = 1; i < $gameMap._event.length; i++) $gameMap.event(i).setStepAnime(true)"

Well, I try a lot of things, but I can't get it to work.
I'll look into this for you when I get some free time tomorrow. I'll post my solution sometime later if I manage to get some free time later!
You could try this.
Code:
var casa = [2, 3, 4, 5];
casa.forEach(function(eventId) {
     $gameMap.event(eventId).setStepAnime(true);
});
I tried something like this:
var temp = $gameMap.events()
temp.forEach(function(element){
element.stepAnime = true
})

When I tried to do it without capturing the array, it didn't work. However, when i assigned the array to a variable, it worked for me
You could try this.
Code:
var casa = [2, 3, 4, 5];
casa.forEach(function(eventId) {
     $gameMap.event(eventId).setStepAnime(true);
});
OHH GOD!!! That's it!!
It also makes me understand properly how to use this type of code!
Thanks a lot!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-use-foreach.110461/