I have this script to target the last game inside an array.
const lastMatch = league.data.schedule.events.pop();
But that pops the last game, which I understand why. I actually want to target the games that are 'completed'.
I tried
const lastMatch = league.data.schedule.events.state('completed');
You can get all the games with the completed
property by using the Array#filter
method.
const completed = games.filter(({ state }) => state === "completed")
This will return a new array with the elements that meet the specified condition.