0

Is there a way to transform the following array of objects:

   array =  [
        { date: "08/18", id: 1 },
        { date: "08/14", id: 2 },
        { date: "08/15", id: 3 }
    ]

Into this? Only returning the dates:

array2 = ["08/18", "08/14", "08/15"]

I've been trying to push the date elements as it follows, but it doesn's seem to work:

array.map(e => {
    array2.push(e.date)
})

Thanks in advance.

Jose Peres
  • 197
  • 1
  • 1
  • 18

1 Answers1

6

You can use the array map function:

array2 = array.map(object => object.date);
Umberto
  • 579
  • 2
  • 10