-1

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');

but can't seem to figure it out. Image of league.data.schedule.events

  • 3
    Does this answer your question? [Find last matching object in array of objects](https://stackoverflow.com/questions/33268863/find-last-matching-object-in-array-of-objects) – pilchard Jan 30 '22 at 22:28

1 Answers1

2

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.

Rida F'kih
  • 239
  • 1
  • 6