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
Syntax
Object.entries(obj)
Parameters
| Parameter | Description |
|---|---|
obj |
The object to inspect or change. |
Return value
An array of [key, value] arrays.
Examples
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
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
| Version | Change |
|---|---|
| JavaScript ES2017 | Added |
In other languages
dict.items()· Python
Related
Object.keys()· Return an array of an object's own enumerable property names, in insertion order (integer keys first).Object.values()· Return an array of an object's own enumerable property values, in the same order as Object.keys().Object.fromEntries()· Build an object from an iterable of [key, value] pairs, such as an array or a Map. The opposite of Object.entries().array.entries()· Return an iterator of [index, element] pairs, handy for looping with both the index and the value.- JavaScript Objects · tutorial