Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JavaScript · Function

Object.entries

Object.entries() returns an array of [key, value] pairs for an object's own enumerable string-keyed properties. It excludes inherited properties and preserves the standard property-enumeration order.

Since
ES2017

How it works

Call Object.entries with an object-like value to receive an array of two-item arrays. Each inner array contains an own enumerable string property key followed by its value; inherited properties are excluded, and the entries follow the object's property enumeration order.

Syntax

Object.entries(obj)

Parameters

NameTypeDescription
objobjectThe value converted to an object and inspected for own enumerable string-keyed properties.

Returns

An array of the object's own enumerable string-keyed property key-value pairs; each pair is a two-element array containing a string key and its value.

Key points

  • It is a static Object method that collects an object's own enumerable string-keyed properties into an array.
  • Every result element is a two-item array whose first item is the property key.
  • Keys in the returned pairs are always strings, while the second item preserves the property value.
  • Its direct-property traversal resembles for...in, but it omits enumerable properties inherited through prototypes.
  • The output array uses the same property enumeration order as for...in.
  • The resulting pairs can be passed directly to Map to construct a map.

Common mistakes

  • Passing undefined or null throws a TypeError instead of producing an empty result.
  • Primitive arguments are coerced: strings can produce character entries, whereas other primitives produce no entries.

Example: Iterate over an object's entries

const user = { name: "Ada", age: 36 };

for (const [key, value] of Object.entries(user)) {
  console.log(`${key}: ${value}`);
}

Iterates through each own enumerable string-keyed property as a two-item array.

When to use it

Iterate over properties

Need to process both names and values in an object.

Create a Map from an object

Need an iterable sequence of pairs for a collection constructor.

Transform entries

Need to transform or filter properties before rebuilding an object.

Interview questions

QWhat does Object.entries return?

Object.entries(obj) returns an array of [key, value] pairs for the object's own enumerable string-keyed properties. Each key is a string, and inherited properties are not included.

Follow-up: How does it differ from for...in? Object.entries excludes prototype-chain properties, while for...in includes enumerable inherited properties.

QWhat is the ordering and shape of the result?

The result is ordered like a for...in enumeration of the object's properties. The returned outer array contains one two-element array per matching property.

Follow-up: How would you get only one side of each pair? Use Object.keys for keys or Object.values for values.

QHow can Object.entries convert an object to a Map?

It can be used with the Map constructor because the result is an iterable list of key-value pairs. For example, new Map(Object.entries(obj)) converts an object into a Map.

Follow-up: What is the reverse operation? Object.fromEntries converts a list of key-value pairs into an object, though it can also create symbol-keyed properties.

  • Object.keys()
  • Object.values()
  • Object.fromEntries()
  • Map()

Source: Object.entries() - JavaScript - MDN Web Docs. Checked 2026-10-15.