JavaScript Object entries() method
returns an array with the key/value pairs of an object

Object.entries() static method returns an array with the key/value pairs of an object.

Object.entries() method returns an array of strings representing the given object's own enumerable string-keyed property entries.

This is the same as iterating with a for...in loop, except that a for...in loop enumerates properties in the prototype chain as well.

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.

syntax

Object.entries(obj)

obj An object.

If you need the property keys, use Object.keys() instead.

If you need the property values, use Object.values() instead.

The order of the array returned is the same as that provided by a for...in loop.

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

const myEntries1 = Object.entries(myObject1);

console.log(myEntries1); returns ↴

[['a', 1], ['b', 2], ['c', 3]]

Using array destructuring, we can iterate through an object

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

for (const [key, value] of Object.entries(myObject2)) {

console.log(`${key}: ${value}`); } returns ↴

a: 1

b: 2

c: 3

Object.fromEntries() performs the reverse of Object.entries(), except that

Object.entries() only returns string-keyed properties, while Object.fromEntries() can also create symbol-keyed properties.

syntax description
return an array with the key/value pairs of an object
Object.entries(myObject)