I have this array of objects...
[
{
"id": 1,
"application": "Default Case Set",
"errorSource": "CASEWORK",
"message": 34,
"stackTrace": 0,
"date": 0,
"user": 0
},
{
"id": 2,
"application": "Default",
"errorSource": "CASEWORK",
"message": 39,
"stackTrace": 2,
"date": 0,
"user": 0
}
]
I would like to create an array of ids that looks like this...
[1, 2]
What is the best way to do this?
Thanks!
Use Array.map to extract the id property value from each object.
const arr = [
{
"id": 1,
"application": "Default Case Set",
"errorSource": "CASEWORK",
"message": 34,
"stackTrace": 0,
"date": 0,
"user": 0
},
{
"id": 2,
"application": "Default",
"errorSource": "CASEWORK",
"message": 39,
"stackTrace": 2,
"date": 0,
"user": 0
}
]
const result = arr.map(e => e.id)
console.log(result)