Reputation: 31
I have an array like this-
[{a:23},{b:23},{r:2323},{e:99}]
I want to convert this to a new array containing only the object property values like-
[23,23,2323,99]
I have tried all the methods but could not figure out the way. Can anyone suggest me the idea for this please.
Upvotes: 1
Views: 86
Reputation: 4780
Just use .flatMap and Object.values
const data = [{a:23}, {b:23}, {r:2323}, {e:99}];
const result = data.flatMap(Object.values);
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0 }
Upvotes: 2