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.



