Object.keys()

Returns an array of an object's own enumerable string-keyed property names.

Since ES5 Spec ↗

Syntax

Object.keys(obj)

Parameters

NameTypeRequiredDescription
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

EnvironmentSince version
chrome 5
firefox 4
safari 5
edge 12
node 0.10

See also