Published Dec 11, 2023
Contribute to Docs

The .entries() method returns an array containing arrays of an object‘s key-value pairs in the following format: [ [key, value], [key, value], ... ].



The above syntax will return the key-value pair entries for someObject.


In the example below, a drink object is declared. Then a for-of loop is used to format the key-value pairs and output them to the console:

const drink = {
name: 'Chai Latte',
size: 'Regular',
price: 2.99,
for (const [key, value] of Object.entries(drink)) {
console.log(`${key.toUpperCase()} ${value}`);

This above example will return the following output:

NAME Chai Latte
SIZE Regular
PRICE 2.99

All contributors

Looking to contribute?

Learn JavaScript on Codecademy