Here is a shorter way of achieving it:
let result = objArray.map(a => a.foo);
OR
let result = objArray.map(({ foo }) => foo)
You can also check Array.prototype.map()
.
More Related Contents:
- How do I correctly clone a JavaScript object?
- How can I check if an object is an array? [duplicate]
- Is Chrome’s JavaScript console lazy about evaluating objects?
- __proto__ VS. prototype in JavaScript
- How to get all properties values of a JavaScript Object (without knowing the keys)?
- How can I display a JavaScript object?
- How to iterate over a JavaScript object?
- Organize prototype javascript while perserving object reference and inheritance
- What are the differences between JSON and JavaScript object? [duplicate]
- Remove property for all objects in array
- How to map more than one property from an array of objects
- How to transpose a javascript object into a key/value array
- Create an object from an array of keys and an array of values
- Sum of array object property values in new array of objects in Javascript [duplicate]
- Getting the first index of an object
- Create an empty object in JavaScript with {} or new Object()?
- How to find duplicate values in a JavaScript array of objects, and output only unique values?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Get the value of an object with an unknown single key in JS
- Encoding Javascript Object to Json string
- Returning only certain properties from an array of objects in Javascript [duplicate]
- Elegant way to copy only a part of an object [duplicate]
- Why can’t I set a JavaScript function’s name property?
- Using JavaScript what’s the quickest way to recursively remove properties and values from an object?
- Is this a good way to clone an object in ES6?
- JavaScript error: “is not a function”
- How to convert array of key–value objects to array of objects with a single property?
- What’s the JavaScript’s Object.prototype behavior?
- JavaScript/JSON: Get unknown property of an object
- Javascript reflection: Get nested objects path