Name
Object.keys() — return own enumerable property names
Availability
ECMAScript 5
Synopsis
Object.keys(o)
Arguments
oAn object
Returns
An array that contains the names of all enumerable own
(non-inherited) properties of o.
Description
Object.keys() returns an
array of property names for the object o.
The array only includes the names of properties that are enumerable
and are defined directly on o: inherited
properties are not included. (See Object.getOwnPropertyNames() for a way to
obtain the names of non-enumerable properties.) Property names
appear in the returned array in the same order they would be
enumerated by a for/in
loop.
Note that this is not a method to be invoked on an object: it is a global function and you must pass an object to it.
Example
Object.keys({x:1,y:2})// => ["x", "y"]
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access