Open In App

JavaScript Object entries() Method

JavaScript Object.entries() method is used to return an array consisting of enumerable property [key, value] pairs of the object which are passed as the parameter. The ordering of the properties is the same as that given by looping over the property values of the object manually.

Syntax:

Object.entries(obj);

Parameters:

Return Value:

Object.entries() returns an array consisting of enumerable property [key, value] pairs of the object passed.



Example 1: In this example, an object “obj” has been created with three property[key, value] pairs, and the Object.entries() method is used to return the first property [key, value] pair of the object.




// Creating an object constructor
// and assigning values to it
const obj = { 0: 'adam', 1: 'billy', 2: 'chris' };
     
// Displaying the enumerable property [key, value]
// pairs of the object using object.entries() method
console.log(Object.entries(obj)[1]);

Output

[ '1', 'billy' ]

Example 2: In this example, an object “obj” has been created with three property[key, value] pairs, and the Object.entries() method is used to return all the property [key, value] pairs of the object. 




// Creating an object constructor and
// assigning values to it
const obj = { 10: 'adam', 200: 'billy', 35: 'chris' };
 
// Displaying the enumerable property [key, value]
// pairs of the object using object.entries() method
console.log(Object.entries(obj));

Output
[ [ '10', 'adam' ], [ '35', 'chris' ], [ '200', 'billy' ] ]

Applications

Exceptions

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers:

Article Tags :