Difference between Object.values and Object.entries Methods
Object.values() method: In the same order as a for…in the loop, the Object.values() method returns an array of the enumerable property values of an object. This is the only difference: a for…in the loop also enumerates properties in the prototype chain.
- Parameter: This object is enumerable with its own properties whose values should be returned.
- Return Type: Array of values
Example: Users can open the console into the chrome web browser by pressing ctrl + shift + I.
["geeks", "for", "geeks"]
This method returns an array of the keys and values of the objects’ enumerable string-keyed properties. It works similarly to iterating with a for…in the loop, with the exception that a for…in the loop also enumerates properties in the prototype chain.
- Parameter: Returns the object’s own enumerable string-keyed property [key, value] pairs.
- Return: This is an array of the given object’s string-keyed property [key, value] pairs.
[["firstname", "geeks"], ["middlename", "for"], ["lastname", "geeks"]]
Difference between object.value and object.entries methods:
object.value object.entries It returns the array of values of a particular object It returns an array of arrays of key-value pair It returns only values of all keys present in an object It returns both keys as well as their values present in an object