How to Get the Values of an Object in JavaScript

Extracting values from JavaScript objects is a fundamental task when processing data from APIs or user input. As the creator of CoreUI with over 25 years of JavaScript development experience, I frequently work with object value extraction in UI components. The most efficient and modern approach is using the Object.values() method, which returns an array of all enumerable property values.

Use Object.values() to extract all values from an object into an array.

const user = { name: 'John', age: 30, city: 'New York' }
const values = Object.values(user)
console.log(values) // ['John', 30, 'New York']

The Object.values() method iterates through all enumerable properties of an object and returns their values as an array. This method only extracts values from the object’s own properties, not inherited ones. The order of values in the returned array matches the order of properties when you iterate over the object. For nested objects, only the direct property values are extracted - nested object structures remain intact.

Best Practice Note:

In CoreUI components, we use Object.values() extensively for form validation, data transformation, and component state processing. This approach ensures clean, readable code when working with configuration objects and user data across our UI library.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to Center a Button in CSS
How to Center a Button in CSS

How to loop through a 2D array in JavaScript
How to loop through a 2D array in JavaScript

How to Add a Tab in HTML
How to Add a Tab in HTML

How to dynamically add, remove, and toggle CSS classes in React.js
How to dynamically add, remove, and toggle CSS classes in React.js

Answers by CoreUI Core Team