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.

1
  • array.map(({date})=>date); Commented Aug 19, 2020 at 21:47

1 Answer 1

6

You can use the array map function:

array2 = array.map(object => object.date);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.