Trusted answers to developer questions

What is the Object.entries() method in JavaScript?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

The object.entries() method returns an array of [key,value] pairs that contain all of the object’s properties. This array only includes the enumerable properties and does not include properties from the prototype chain.

Enumerable properties are properties created with simple assignment or with a property initializer.

The order of the properties is the same as that given by looping over the property values of the object manually.

Syntax

The function takes an object whose enumerable property (i.e.,[key, value] pair) is to be returned. It returns an array containing these properties.

Object.entries(obj)

Code

The following code demonstrates the use of the Javascript object.entries() method.

// A map object
const obj = { 'adam': 100, 'smith': 40, 'jon': 62 };
// The object.entries method converts this map
// object into array of properties
console.log(Object.entries(obj));
// Accessing the second property of this array.
console.log(Object.entries(obj)[1]);

RELATED TAGS

javascript
object
entries
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?