Object.entries() method

The JavaScript Object.entries function serves to produce an array consisting of an object's own enumerable property [key, value] pairs. The sequence of these properties corresponds to the order in which one would traverse the property values of the object in a manual iteration.

Syntax:

Example

Object.entries(obj)

Parameter

Obj: It refers to an object that is intended to return its enumerable properties as [key, value] pairs.

Return value:

This approach yields an array consisting of the object's own enumerable property [key, value] pairs.

Browser Support:

Chrome 38
Edge Yes
Firefox 28
Opera No

Example 1

Example

const obj = { 10: 'arry', 21: 'barry', 23: 'carry' };
console.log(Object.entries(obj)[2]);

Output:

Output

["23", "carry"]

Example 2

Example

// creating an object constructor.
  // and assigning values to it. 
const obj = { 1: 'marrc', 2: 'sort', 3: 'carry' };
 
   // Displaying the countable property [key, value] 
   // pairs of the object using object.entries() method. 
console.log(Object.entries(obj)[2]);//access obj.

Output:

Output

["3", "carry"]

Example 3

Example

// creating an object constructor.
  // and assigning values to it. 
const obj2 = { 10: 'arvind', 2: 'rahul', 7: 'Ankit' };

    // Displaying the countable property [key, value] 
   // pairs of the object using object.entries() method. 
console.log(Object.entries(obj2)[2]);

Output:

Output

["10", "arvind"]

Input Required

This code uses input(). Please provide values below: