My API hands me this array of objects:
[
{ id: 5, name: "foo" },
{ id: 7, name: "bar" }
]
I would like to filter out the ID keys and achieve this:
[5,7]
What would be considered best practice in this case?
My API hands me this array of objects:
[
{ id: 5, name: "foo" },
{ id: 7, name: "bar" }
]
I would like to filter out the ID keys and achieve this:
[5,7]
What would be considered best practice in this case?
Just use array.map:
var data = [
{ id: 5, name: "foo" },
{ id: 7, name: "bar" }
];
var res = data.map(({id}) => id);
console.log(res);