Object.entries()

Object.entries(obj)
Returns: Array · Updated March 13, 2026 · Object Methods
javascript object entries enumerable

Object.entries() returns an array of a given object’s own enumerable string-keyed property [key, value] pairs. The order matches that of a for...in loop, except inherited properties are excluded.

Syntax

Object.entries(obj)

Parameters

ParameterTypeDefaultDescription
objObjectrequiredThe object whose own enumerable string-keyed property [key, value] pairs are to be returned.

Return Value

An array of [key, value] pairs for each of the object’s own enumerable string-keyed properties.

Examples

Basic usage

const obj = { a: 1, b: 2, c: 3 };

console.log(Object.entries(obj));
// [['a', 1], ['b', 2], ['c', 3]]

Destructuring in a loop

const user = { name: 'Alice', age: 30, role: 'admin' };

for (const [key, value] of Object.entries(user)) {
  console.log(`${key}: ${value}`);
}
// name: Alice
// age: 30
// role: admin

Converting to a Map

const obj = { one: 1, two: 2, three: 3 };

const map = new Map(Object.entries(obj));
console.log(map.get('two'));
// 2

Non-enumerable properties are excluded

const obj = Object.create({}, {
  hidden: { value: 'secret', enumerable: false },
  visible: { value: 'public', enumerable: true }
});

console.log(Object.entries(obj));
// [['visible', 'public']]

Common Patterns

Filtering object properties

const scores = { alice: 85, bob: 42, charlie: 91, diana: 58 };

const passing = Object.fromEntries(
  Object.entries(scores).filter(([, score]) => score >= 60)
);

console.log(passing);
// { alice: 85, charlie: 91 }

Transforming values

const prices = { apple: 1.5, banana: 0.75, cherry: 3.0 };

const discounted = Object.fromEntries(
  Object.entries(prices).map(([item, price]) => [item, price * 0.9])
);

console.log(discounted);
// { apple: 1.35, banana: 0.675, cherry: 2.7 }

Sorting object by value

const scores = { alice: 85, bob: 42, charlie: 91 };

const sorted = Object.fromEntries(
  Object.entries(scores).sort(([, a], [, b]) => b - a)
);

console.log(sorted);
// { charlie: 91, alice: 85, bob: 42 }

See Also