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
Syntax
Object.keys(obj)
Parameters
| Parameter | Description |
|---|---|
obj |
The object to inspect or change. |
Return value
An array of strings.
Examples
const user = { name: "Ada", role: "admin" };
console.log(Object.keys(user), Object.keys(user).length);
Output
[ 'name', 'role' ] 2
console.log(Object.keys({ b: 1, 2: "x", a: 2, 1: "y" }));
Output
[ '1', '2', 'b', 'a' ]
Version history
| Version | Change |
|---|---|
| JavaScript ES5 | Added |
In other languages
dict.keys()· Pythonarray_keys()· PHP
Related
Object.values()· Return an array of an object's own enumerable property values, in the same order as Object.keys().Object.entries()· Return an array of an object's own enumerable [key, value] pairs, ready for for…of loops or array methods.Object.getOwnPropertyNames()· Return all own string property names, including non-enumerable ones that Object.keys() skips.- JavaScript Objects · tutorial