Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.entries: own key–value pairs

Object.entries returns a new array of pairs for enumerable own properties whose keys are strings.

Version: ECMAScript 2017 onward; example target: Node.js 24.22.2

Syntax

Object.entries(value)

Object.entries(value) first performs ToObject: null and undefined throw TypeError, while other primitives are boxed. A string therefore produces pairs for its enumerable character indices. The result is a new array of two-element [key, value] arrays, with string keys.

Only enumerable own properties with string keys are included. Symbol keys, inherited properties, and non-enumerable properties are skipped. Ordering follows OwnPropertyKeys: array-index keys are ascending numerically, while other string keys retain creation order.

The method has existed since ECMAScript 2017. The key list is first snapshotted, but for each key the method checks its current own descriptor again and then gets its value. Getters and Proxy traps can therefore mutate the object, remove later keys, or throw; the result is not an atomic snapshot of values.

Examples

const symbol = Symbol("skip");
const proto = { inherited: "skip" };
const record = Object.create(proto);
Object.defineProperty(record, "first", {
  enumerable: true,
  configurable: true,
  get() { delete record.later; return "A"; }
});
record.later = "B";
record[2] = "two";
record[1] = "one";
Object.defineProperty(record, "hidden", { value: 0 });
record[symbol] = "symbol";
console.log(JSON.stringify(Object.entries(record)));
console.log(JSON.stringify(Object.entries("hi")));
try { Object.entries(null); } catch (error) { console.log(error.name); }

Result

[["1","one"],["2","two"],["first","A"]]
[["0","h"],["1","i"]]
TypeError

The example shows key ordering, omission of symbols and inheritance, and a getter deleting a later key.

Sources