Rehan Sattar
Rehan Sattar

Follow

Rehan Sattar

Follow
Understanding Object.values()

Understanding Object.values()

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

Rehan Sattar 's photo
Rehan Sattar
·Jun 18, 2021
Play this article

👉 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()

  1. It returns the elements in the same order as that provided by a for...in loop.
  2. The only difference is that a for...in loop enumerates properties in the prototype chain as well.
  3. The result of Object.values() is an array of all the values so you can map all the array methods to it.
  4. 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:

 
Share this