Technique 1 : Object.entries
Object.entries() returns a list of key, value pairs. This list includes only enumerable properties and doesn’t include properties from prototype chain.
Properties created via simple assignment or via a property initializer
Technique 2 : Object.keys
Object.keys() returns an array of object keys. However, this function returns only enumerable properties.
Technique 3 : Object.values
Object.values() returns an array of object property values. This function returns values of enumerable properties only.
Technique 4 : for…in loop
Technique 5 : Object.getOwnPropertyNames
Object.getOwnPropertyNames returns all the properties of an object including non enumerable properties. The result set will also include properties inherited from prototype chain.
In order to compare the performance of each of above techniques, following script was executed for 1000 objects having 1 million properties in each.
Chart below gives a better comparison overview of the techniques.
Call To Action
Originally published at gists.cwidanage.com.