Get an array of property values from an object array
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Extracting an array of property values from an array of objects is one of the most common data transformation tasks in JavaScript. The standard approach is array.map(obj => obj.property), which creates a new array containing only the specified property from each object. For nested properties, optional chaining (?.) prevents errors on missing keys. Destructuring, Array.from(), and lodash's _.map or _.pluck offer alternative patterns for different use cases.
Using map() (Recommended)
Array.map() creates a new array by applying the callback to each element. It does not mutate the original array.
Nested Property Extraction
Optional chaining (?.) returns undefined instead of throwing a TypeError when a property in the chain is null or undefined.
Using flatMap() for Multiple Values
flatMap() maps each element and then flattens the result by one level — perfect for extracting arrays from objects and merging them.
Using reduce() for Grouped Extraction
Reusable Property Extractor
TypeScript Version
Common Pitfalls
- Missing property returns
undefined:[{a:1}, {b:2}].map(o => o.a)returns[1, undefined]. Use optional chaining andfilter(Boolean)or a default value to handle missing properties. - Mutating objects inside
map():map()should be a pure transformation. Modifying the source objects (e.g.,user.name = user.name.toUpperCase()) inside the callback mutates the original array. - Using
for...ininstead ofmap():for...initerates over all enumerable properties including inherited ones. Always usemap(),for...of, orforEach()for array iteration. - Forgetting that
map()preserves array length: Unlikefilter(),map()always returns an array the same length as the input. Use.filter()after.map()or.flatMap()to remove unwanted entries. - String property access on null/undefined:
obj[key]throws ifobjisnullorundefined. When the array may contain null entries, filter them first or use optional chaining:arr.map(o => o?.[key]).
Summary
array.map(obj => obj.prop)— standard approach for extracting a property from each object- Use optional chaining (
?.) for safe nested property access flatMap()— extract and flatten array properties from objectsreduce()— group or aggregate property values- Destructuring in the callback —
map(({ name }) => name)for cleaner syntax - Generic
pluck(arr, key)function for reusable property extraction
Related reading
- Get difference between two lists with Unique Entries
- Get difference between two lists with Unique Entries
- Get exception description and stack trace which caused an exception, all as a string
- Get file's size from bytes array without saving to disc
- get and set in TypeScript
- Get current scroll position of ScrollView in React Native
- Get first element from a dictionary
- Get first key in a (possibly) associative array?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.