Object.entries()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
TheObject.entries() static method returns an array of a given object's own enumerable string-keyed property key-value pairs.
In this article
Try it
const object = { a: "some string", b: 42,};for (const [key, value] of Object.entries(object)) { console.log(`${key}: ${value}`);}// Expected output:// "a: some string"// "b: 42"Syntax
Object.entries(obj)Parameters
objAn object.
Return value
An array of the given object's own enumerable string-keyed property key-value pairs. Each key-value pair is an array with two elements: the first element is the property key (which is always a string), and the second element is the property value.
Description
Object.entries() returns an array whose elements are arrays corresponding to the enumerable string-keyed property key-value pairs found directly uponobject. This is the same as iterating with afor...in loop, except that afor...in loop enumerates properties in the prototype chain as well. The order of the array returned byObject.entries() is the same as that provided by afor...in loop.
If you only need the property keys, useObject.keys() instead. If you only need the property values, useObject.values() instead.
Examples
>Using Object.entries()
const obj = { foo: "bar", baz: 42 };console.log(Object.entries(obj)); // [ ['foo', 'bar'], ['baz', 42] ]const arrayLike = { 0: "a", 1: "b", 2: "c" };console.log(Object.entries(arrayLike)); // [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ]const randomKeyOrder = { 100: "a", 2: "b", 7: "c" };console.log(Object.entries(randomKeyOrder)); // [ ['2', 'b'], ['7', 'c'], ['100', 'a'] ]// getFoo is a non-enumerable propertyconst myObj = Object.create( {}, { getFoo: { value() { return this.foo; }, }, },);myObj.foo = "bar";console.log(Object.entries(myObj)); // [ ['foo', 'bar'] ]Using Object.entries() on primitives
Non-object arguments arecoerced to objects.undefined andnull cannot be coerced to objects and throw aTypeError upfront. Only strings may have own enumerable properties, while all other primitives return an empty array.
// Strings have indices as enumerable own propertiesconsole.log(Object.entries("foo")); // [ ['0', 'f'], ['1', 'o'], ['2', 'o'] ]// Other primitives except undefined and null have no own propertiesconsole.log(Object.entries(100)); // []Converting an Object to a Map
TheMap() constructor accepts an iterable ofentries. WithObject.entries, you can easily convert fromObject toMap:
const obj = { foo: "bar", baz: 42 };const map = new Map(Object.entries(obj));console.log(map); // Map(2) {"foo" => "bar", "baz" => 42}Iterating through an Object
Usingarray destructuring, you can iterate through objects easily.
// Using for...of loopconst obj = { a: 5, b: 7, c: 9 };for (const [key, value] of Object.entries(obj)) { console.log(`${key} ${value}`); // "a 5", "b 7", "c 9"}// Using array methodsObject.entries(obj).forEach(([key, value]) => { console.log(`${key} ${value}`); // "a 5", "b 7", "c 9"});Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-object.entries> |