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.
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)
The following code demonstrates the use of the Javascript object.entries()
method.
// A map objectconst obj = { 'adam': 100, 'smith': 40, 'jon': 62 };// The object.entries method converts this map// object into array of propertiesconsole.log(Object.entries(obj));// Accessing the second property of this array.console.log(Object.entries(obj)[1]);
Free Resources