-1

when getting the data from the observer in the console I have this:

enter image description here

however, I only need to get this data from each of the list:

enter image description here

to get the observer I just need to do:

this.item.specialties

How can I get an array with only the id? Thanks in advance

  • Possible duplicate of https://stackoverflow.com/questions/7364150/find-object-by-id-in-an-array-of-javascript-objects – Estus Flask May 03 '22 at 20:57
  • Thanks, looking for an answer I found an easy way to access the data individually I just use `this.item.specialties[1].id` – Daniel Gironás May 03 '22 at 22:02

1 Answers1

1

Use Array.prototype.map() to map the array into a new array.

Assuming this.item.specialties is an array of objects, each containing an id property, you would do this:

const ids = this.item.specialties.map(item => item.id)
tony19
  • 125,647
  • 18
  • 229
  • 307