Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
object
values
communitycreator

What is Object.values in JavaScript?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

By using Object.values, we can get the values of the object. This method will return an array that contains the object’s own enumerable property values. The order of the returned values is the same as the order that it occurs in the for…in loop.

Syntax

Object.values(obj)

Example

let employee = {companyName : "Educative"};
let manager = Object.create(employee);
manager.name = "Ram";
manager.designation = "Manager";
manager.getName = function(){
return this.name;
}
manager[Symbol("symbol")] = "symbol";
Object.defineProperty(manager, "non-enumerable", {
enumerable: false
})
console.log("The manager object is ", manager);
console.log("\nValues of the manager object is ", Object.values(manager))
// the values of non-enumerable properties,symbols and inherited properties are not included in the keys

In the above code, we have:

  1. Created the manager object from the employee object.
  2. Added symbol as a property key to the manager object.
  3. Added a non-enumerable property to the manager object.

When we call the Object.values method by passing the manager object as an argument, we will get an array of its own object property values. The returned array doesn’t include the values of:

  1. Symbols
  2. Inherited propertiesIn our case, employee object properties are inherited properties, so those property values are not included.
  3. Non-enumerable propertiesThe properties that don’t occur in the for…in loop; in our case, the non-enumerable property of manager object.

RELATED TAGS

javascript
object
values
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring