$dataMap.events.filter not working ?

hi.


What am doing wrong.


I try many way but its return all way error in console log.


Am try get a list of all Event have spécific name in the the $dataMap.events[x]._name 


What am do bad ?
How to do this ?


Var NumGalaxi = $dataMap.events.filter(function(event) {
return event._name.includes('soleil');
});


Tanks
The 'v' in 'var' is uppercase, which will cause an error. Also, $dataMap.events has a null entry at position zero, so you need to check to see if each entry actually exists.

Code:
var NumGalaxi = $dataMap.events.filter(function(event) {
                    if (event) return event.name.includes('soleil');
                });
The 'v' in 'var' is uppercase, which will cause an error. Also, $dataMap.events has a null entry at position zero, so you need to check to see if each entry actually exists.



var NumGalaxi = $dataMap.events.filter(function(event) {
if (event) return event.name.includes('soleil');
});



Ok, i just found i way,  i found this is work.


What the difference ??

Code:
$dataMap.events.filter(function(event) {
        return event && event.name=="soleil";
    });
Basically the same thing as I showed above, just using different code.


My code >> If the event is not undefined (exists), then return if the event name includes 'soleil'.


Your code >> return if the event is not undefined (exists) and also the name of the event is equal to 'soleil'.


The original code caused an error because we are trying to call the 'includes' method. We cannot call the 'includes' method on an undefined variable.
Basically the same thing as I showed above, just using different code.


My code >> If the event is not undefined (exists), then return if the event name includes 'soleil'.


Your code >> return if the event is not undefined (exists) and also the name of the event is equal to 'soleil'.


The original code caused an error because we are trying to call the 'includes' method. We cannot call the 'includes' method on an undefined variable.

ok tanks for this explaine.

Original thread: https://forums.rpgmakerweb.com/threads/datamap-events-filter-not-working.67857/