The Object.keys() method returns an array of a given object's own enumerable property names.
Example
keys() Syntax
The syntax of the keys() method is:
Object.keys(obj)
The keys() method, being a static method, is called using the Object class name.
keys() Parameters
The keys() method takes in:
- obj - the object whose enumerable properties are to be returned.
keys() Return Value
The keys() method returns an array of strings that represent all the enumerable properties of the given object.
Note: The ordering of the properties is the same as that when looping over them manually.
Example: Using Object.keys()
Output
[ '0', '1', '2' ] [ '65', '66', '67' ] [ '22', '42', '71' ] [ '0', '1', '2', '3' ]
Recommended Reading: