VOOZH about

URL: https://www.geeksforgeeks.org/web-tech/javascript-keys-values-enteries/

⇱ JavaScript Keys, Values & Enteries - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Keys, Values & Enteries

Last Updated : 27 Jan, 2026

JavaScript offers built-in methods that simplify working with object data. Object.entries(), Object.keys(), and Object.values() help extract and manipulate object properties efficiently.

  • Object.keys() returns an array of all property names (keys) of an object.
  • Object.values() returns an array of all property values.
  • Object.entries() returns an array of key–value pairs, useful for iteration and transformations.

Object.entries()

The Object.entries() method returns an array of a given object's own enumerable property [key, value] pairs.

Output:

[ [ 'name', 'Prakash' ], [ 'age', 99 ], [ 'city', 'Mumbai' ] ]

As you can see, Object.entries(obj) returns an array of arrays, where each inner array contains a key-value pair from the object.

Object.keys()

The Object.keys() method returns an array of a given object's own enumerable property names, iterated in the same order that a normal loop would.

Output:

[ 'name', 'age', 'city' ]

Object.keys(obj) returns an array containing the keys of the object.

Object.values()

The Object.values() method returns an array of a given object's own enumerable property values, in the same order as provided by a for...in loop.

Output:

[ 'Prakash', 99, 'Mumbai' ]

Object.values(obj) returns an array containing the values of the object.

Practical Use Cases

Summing Values

Suppose you have an object with numerical values, and you want to find the sum of these values. Here's how you can do it:


Output
20

Checking for Property Existence

You can check if a property exists in an object using the in operator:


Output
true
true
false

Iterating Over an Object

You can use a for...in loop to iterate over the keys of an object:

Comment