Function that gets all the event IDs of events in a region

I am assuming that I can assign an element of an array into a variable, i.e. the script call:

functionName.functionArray($gameVariables.value(y))

This is hopefully a simple plugin and possibly just programming practice for some but for the life of me I can't seem to write it on my own. I've been asking a friend who's an advanced programmer but there seems to be some MV-related syntax that we just don't know.

Anyway as the title says, I want a plugin that goes through all of the events on a certain region ID, and lists their event IDs in an array.

For example, a map has 20 events. 10 of them are on tiles marked region 3. If I run a script/plugin call, I will get an array that lists down the event IDs of these 10 events. That simple. It won't be helpful to a lot of people but it will really do wonders for me.

Thanks in advance!
I can't run MV at the moment because it's trying to update any my work network won't let Steam connect to it (meaning I can't run it offline either unfortunately) so I can't do this for you right now but when I get home if nobody else has posted a solution I'll whip up a function for you.
$gameMap._events is an array of events on the map. Each event has a regionId() method. It should be possible to use an array method to get the _eventId properties for each event.
Code:
var eventIds = $gameMap._events.map(function (event, eventId) {
    if (event.regionId() === 0) {
        return eventId;
    }
});
Then we can do up our own function.
Code:
function getEventsByRegionId(regionId) {
    return $gameMap._events.map(function (event, eventId) {
        if (event.regionId() === regionId) {
            return eventId;
        }
    });
}
$gameMap._events is an array of events on the map. Each event has a regionId() method. It should be possible to use an array method to get the _eventId properties for each event.
Code:
var eventIds = $gameMap._events.map(function (event, eventId) {
    if (event.regionId() === 0) {
        return eventId;
    }
});
Then we can do up our own function.
Code:
function getEventsByRegionId(regionId) {
    return $gameMap._events.map(function (event, eventId) {
        if (event.regionId() === regionId) {
            return eventId;
        }
    });
}

Oh wow and the way we were trying it was so complicated! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/function-that-gets-all-the-event-ids-of-events-in-a-region.80824/