Understanding Object.values()
A quick guide to understanding `Object.values()`

π The Object.values() method returns an array of all the property values of an object.
π Syntax
Object.values(object);
π Here are some of the major points you have to remember while using Object.values()
- It returns the elements in the same order as that provided by a
for...inloop. - The only difference is that a
for...inloop enumerates properties in the prototype chain as well. - The result of
Object.values()is an array of all the values so you can map all the array methods to it. - This method became part of JavaScript in ES2017.
π Example:
const user = {
name: 'Jhon doe',
age: 34,
isActive: false
};
// Using `for...in`
for (let key in user) {
console.log(user[key]);
}
// Using `Object.values()`
Object.values(user).forEach(value => console.log(value));
π References:
π Follow me:
About the author
A Full Stack Software Engineer(JavaScript) whoβs passionate about creating content that can be of value to others. Besides juggling work, content creation and other commitments, I can be found traveling to contemplate the meaning of life under the stars π
Comments
Join the discussionThis article is amazingπ₯π₯. I never thought of the difference of for...in loop and Object.values (). After reading every article of the Rehan, I always learn something new.π€©π€©
Thank you so much HINA! Keep reading :D




