Name

Object.keys() — return own enumerable property names

Availability

ECMAScript 5

Synopsis

Object.keys(o)

Arguments

o

An 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"]

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.