JavaScript .entries()
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], ... ].
Syntax
Object.entries(someObject)
The above syntax will return the key-value pair entries for someObject.
Example
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 LatteSIZE RegularPRICE 2.99
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours