Open In App

What is the difference between Object.keys() and Object.entries() methods in JavaScript ?

The Object.keys() method in JavaScript returns an array whose elements are strings corresponding to the enumerable properties

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



The only difference is that the Object.keys() method returns only the own property names and it only works for ES5 while Object.entries() method returns an array of arrays with key and value and it works from ES6.

Example 1: This example implements the Object.keys() method.



Example 2: This example implements the Object.entries() method.


Article Tags :