-2

I have array

Game: [
  { game: 'SS', status: 2 },
  { game: 'CD', status: 2 },
  { game: 'AS', status: 2 },
  { game: 'SM', status: 2 },
  { game: 'GTA', status: 1 },
]

how can I find the GTA's status is equal to 1 using find method in js?

Prash
  • 27
  • 4
  • `const foundGame = Game.find(({ status }) => status === 1)` ? – Kunal Mukherjee Nov 02 '20 at 12:42
  • [MDN's documentation of `find`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) has several examples. What part of those are you not understanding? – Heretic Monkey Nov 02 '20 at 12:43

2 Answers2

0

You can use filter method:

const games = Game.filter(gta => gta.status == 1 );
Ivan Shatsky
  • 13,267
  • 2
  • 21
  • 37
Youba
  • 2,636
  • 3
  • 11
  • 25
0
Game.find(game => game.status===1)
Tooba Ali
  • 344
  • 2
  • 5