Object.entries()

const obj = {
	a: 42,
	b: 43
}
for (let [key, value] of Object.entries(obj)) {
	console.log(key, value)
}
// a, 42
// b, 43

Description

Loops over an Object and gives us access to every single entry. Can be used to destructure key and value

Parameters

Obj

Return Value

An array of arrays consisting of the key, value pairs.

const obj = { foo: "bar", baz: 42 };
console.log(Object.entries(obj)); // [ ['foo', 'bar'], ['baz', 42] ]

Example

References