MV Event Name

I learned to access an event by it's ID using $gameMap.event(eventID), but event ID's can vary depending on the order in which they were added to the map. I'd like to access an event by its name instead. In Javascript, how do I access an event by its name?
$gameMap.event(eventID)
I learned to access an event by it's ID using $gameMap.event(eventID), but event ID's can vary depending on the order in which they were added to the map. I'd like to access an event by its name instead. In Javascript, how do I access an event by its name?
Hi there!

It should be: $gameMap.event(1).event().name

Edit: Oh I don't know how to read.... 😀

Code:
// Event array
$gameMap.events().filter(ev => {
    return (ev) ? ev.event().name == "event_name" : false;
});

// First occurance
$gameMap.events().find(ev => {
    return ev.event().name == "event_name";
});
the name is a sub-property of the event and you can't use it as a direct reference.

what you can do is check all events for a name and store/remember the IDs of the events where the name fits, then use those IDs as further reference.
Thanks OcRam! With your help, I was able to create this handy function so I could search an event by name.
Code:
findEventByName = function(event_name) {
    var myEvent = $gameMap.events().find(ev => {
        return ev.event().name == event_name;
    })
    return myEvent;
}
Also
Thanks OcRam! With your help, I was able to create this handy function so I could search an event by name.
Code:
findEventByName = function(event_name) {
    var myEvent = $gameMap.events().find(ev => {
        return ev.event().name == event_name;
    })
    return myEvent;
}
And if you want to bind function to Game_Map then:

Code:
// Array of events
Game_Map.prototype.findEventsByName = function (event_name) {
    return this._events.filter(ev => {
        return (ev) ? ev.event().name == event_name : false;
    });
};

// Or first occurance
Game_Map.prototype.findEventByName = function (event_name) {
    return this._events.find(ev => {
        return ev.event().name == event_name;
    });
};

// Usage would be: $gameMap.findEventByName('My_Event');

Original thread: https://forums.rpgmakerweb.com/threads/event-name.133850/