0

How to get item where id is: '60da3d5ce6cdd45d6dbc56bd'?

enter image description here

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
shanksu 218
  • 185
  • 1
  • 14
  • Could you describe your case better: what the structure of your data is, provide an example in code? Did you try this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find? – Źmicier Jaraševič Dec 11 '21 at 11:09

1 Answers1

0

Use

It will return the first value satisfying condition

Something like:

const data = [
  [{_id: 1}, {_id: 2}, {_id: 2}, {_id: '60da3d5ce6cdd45d6dbc56bd'}],
  [{_id: 1}, {_id: 2}, {_id: 2}],
  [{_id: 1}, {_id: 2}, {_id: 2}]
]

data.flat().find(e => e._id === '60da3d5ce6cdd45d6dbc56bd')
// output { _id: '60da3d5ce6cdd45d6dbc56bd' }

works just fine

millenion
  • 1,218
  • 12
  • 16