Object.keys()
Returns an array of an object's own enumerable string-keyed property names.
Syntax
Object.keys(obj) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | The object whose enumerable own property names are returned. |
Returns
Array — An array of strings representing the own enumerable property keys.
Examples
console.log(Object.keys({ a: 1, b: 2 }));
Output
[ 'a', 'b' ]
console.log(Object.keys('abc'));
Output
[ '0', '1', '2' ]
Notes
Only includes own enumerable string keys - not inherited or symbol keys.
Integer-like keys come first in ascending order, then string keys in insertion
order.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 5 |
| firefox | 4 |
| safari | 5 |
| edge | 12 |
| node | 0.10 |