I have an array with objects returned by a server like this:
myArr = [{
"id": 1
}, {
"id": 2
}, {
"id": 3
}, {
"id": 4
}, {
"id": 5
}, {
"id": 6
}, {
"id": 7
}, {
"id": 8
}, {
"id": 9
}, {
"id": 10
}];
I need this to become:
myArr = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
];
I can loop through the array of course, something like:
// array to hold property values
let myNewArr = [];
// loop through the objects and take the value of id of each object
for (let i = 0; i < myArr.length; ++i) {
myNewArr.push(myArr[i].id);
}
Is there a more efficient way to do this, preferably using Lodash? I don't want to add another loop to the code, as it's already riddled with loops.