MZ How to check number of events on the map?

Hey, guys! Got a JS question that I'm not sure is even possible. I'd really appreciate the help, even if it's just to tell me it's impossible.

Short version: Is there a way to check how many events named "Enemy" are currently on the map? i.e., Is there a way to get a list/array (whatever you call it in JS) of events that have a specific property and get the length of that list?

Longer explanation:
I've started using VisuStella's Random Dungeon Maps plugin to create roguelike-style dungeons. From what I understand, this works by piecing together a set of Cell Maps and placing events found in a designated Container Map. These events have names like Exit, Goal, and Enemy. Enemies and treasure chests can be given percent chances to appear. Thus, each generated map will have a different number of enemies. I was hoping to have challenges on some dungeon floors like "Defeat all enemies," and to do that, I need to know how many enemies have been spawned onto the map. I would have an auto run event set a variable to some script that checks how many events currently on the map have the name "Enemy." Then, each time the player defeats an enemy, that enemy's respective event decrements that variable. When the variable hits 0, the Goal event unlocks. Is there a way to get a list/array (whatever the JS term is) of events with a specific property like a name? I imagine it would involve using loops to iterate through each event and check its name. If the name matches "Enemy," add it to the list. Once all events are checked, get the length of the list. But can I do that for a random number of events?
In the Script field of Control Variables:
Code:
$gameMap.events().filter(event => event.event().name == "Enemy").length

That's presuming the VisuStella plugin places spawned events into the same array in the map as predefined events...which I think is a reasonable assumption, but an assumption nonetheless.
In the Script field of Control Variables:
Code:
$gameMap.events().filter(event => event.event().name == "Enemy").length

That's presuming the VisuStella plugin places spawned events into the same array in the map as predefined events...which I think is a reasonable assumption, but an assumption nonetheless.
That worked perfectly! Thanks a lot.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-number-of-events-on-the-map.165617/