Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.keys — own enumerable object keys

Object.keys(obj) returns a new array of an object's own enumerable string keys. It excludes inherited properties, non-enumerable properties, and Symbol keys. For ordinary objects, array-index keys appear before the remaining string keys.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object.keys(obj)

Object.keys(obj) is a static method of Object that returns a new array of property names. It includes only own properties, meaning properties not inherited from a prototype, whose enumerable attribute is true and whose key is a string. The result contains strings even when keys were written as numbers. Symbol keys are excluded.

For ordinary objects, array-index keys appear in ascending numeric order, followed by other string keys in property creation order. This is neither alphabetical sorting nor a rule for every numeric-looking string: "02" is not an array index. Proxy objects can influence the order and execute code during enumeration.

Unlike for...in, the method excludes inherited enumerable properties. In contrast, Reflect.ownKeys(obj) also includes own non-enumerable properties and Symbol keys. Object.keys itself does not read property values or invoke their getters; the returned array does not update when the object changes.

null and undefined cause a TypeError. Other primitive values are converted to objects: Object.keys("ab") produces ["0","1"], whereas Object.keys(42) produces []. This is an ECMAScript language API, not a browser API; running the example in Node.js does not establish compatibility with a particular browser.

Examples

const item = Object.create({ inherited: true });
item.name = "Ada";
item[10] = "ten";
item[2] = "two";
Object.defineProperty(item, "hidden", { value: true });
item[Symbol("tag")] = true;

console.log(JSON.stringify(Object.keys(item)));

Result

["2","10","name"]

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources