Return an array of an object's own enumerable property names.
The Object.keys() method returns an array of a given object's own enumerable string-keyed property names. The order of the array matches the order returned by a for...in loop, except that Object.keys() does not include inherited properties.
This method is commonly used to iterate over the properties of a plain object, count properties, or convert an object into an array-based representation for further processing with array methods.
If a non-object value is passed, it is coerced to an object. Passing null or undefined throws a TypeError. For arrays, Object.keys() returns the indices as strings.
| Name | Description | Optional |
|---|---|---|
obj |
The object whose enumerable property names are to be returned. | No |
Object.keys({ a: 1, b: 2, c: 3 });
// ['a', 'b', 'c']