-2

I have an array like this.

[
{
  "id": 13,
  "name": "VA"
},
{
  "id": 14,
  "name": "NA"
},
{
  "id": 15,
  "name": "PA"
}

]

I need a new array with all id values like this [13,14,15]. Using javascript.

Gaurav Kandpal
  • 1,250
  • 2
  • 15
  • 33
  • StackOverflow is not a code writing service. We expect to see some attempt at solving the issue yourself. A coded example of what you have tried is good, if you don't have that, tell us what your research so far has shown you – Jon P Aug 14 '19 at 05:26

1 Answers1

0

Use map

var a=[
{
  "id": 13,
  "name": "VA"
},
{
  "id": 14,
  "name": "NA"
},
{
  "id": 15,
  "name": "PA"
}

]
console.log(a.map(e=>e.id))
ellipsis
  • 12,049
  • 2
  • 17
  • 33