I've got an array of sessions defined something like this:
const sessions = [{id: 1, eventYear: "2019"},{id: 2, eventYear: "2018"},{id: 3, eventYear: "2018"}];
and I want to create a new array of objects with just the eventYear "2018"
I tried mapping over the array and if session.eventYear === eventYear
return the session record, otherwise return nothing, but got a list of objects 3 long (not 2) with one undefined record. I wanted just 2 records returned.
I have the following working, but it feels uncomfortably non functional and long. I'd appreciate a suggestion for how to make this more concise in modern JavaScript
const sessionsForEventYear = [];
sessions.map(function(session) {
if (session.eventYear === eventYear) {
sessionsForEventYear.push(session);
}
});