JavaScript (ES2026) reference · Object Methods

JavaScript Object.keys() Method

Return an array of an object's own enumerable property names, in insertion order (integer keys first).

JavaScript (ES2026) Since ES5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.keys(obj)

Parameters

ParameterDescription
obj The object to inspect or change.

Return value

An array of strings.

Examples

List the keysTry it yourself
const user = { name: "Ada", role: "admin" };
console.log(Object.keys(user), Object.keys(user).length);

Output

[ 'name', 'role' ] 2
Integer-like keys come firstTry it yourself
console.log(Object.keys({ b: 1, 2: "x", a: 2, 1: "y" }));

Output

[ '1', '2', 'b', 'a' ]

Version history

VersionChange
JavaScript ES5Added

In other languages

Was this page helpful?