JavaScript (ES2026) reference · Object Methods

JavaScript Object.entries() Method

Return an array of an object's own enumerable [key, value] pairs, ready for for…of loops or array methods.

JavaScript (ES2026) Since ES2017

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.entries(obj)

Parameters

ParameterDescription
obj The object to inspect or change.

Return value

An array of [key, value] arrays.

Examples

Loop over keys and valuesTry it yourself
const prices = { tea: 3, cake: 4.5 };
for (const [item, price] of Object.entries(prices)) {
  console.log(`${item}: ${price}`);
}

Output

tea: 3
cake: 4.5
Filter an objectTry it yourself
const stock = { apples: 5, pears: 0, plums: 12 };
console.log(Object.fromEntries(Object.entries(stock).filter(([, n]) => n > 0)));

Output

{ apples: 5, plums: 12 }

Version history

VersionChange
JavaScript ES2017Added

In other languages

Was this page helpful?