Object.keys(obj) Last updated: 17. Oct 2026
Returns the names of an object's own properties. Works for object literals, JSON data from documents, and Docly objects such as request. Object.values() returns the values in the same order.
See also: Object.entries
Parameters
| Name | Type | Description |
|---|---|---|
| obj | object | The object to read property names from. |
Returns
An array of property names. For an array or a text, the indexes. For null or undefined, null (standard JavaScript throws a TypeError).
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.const person = { name: "Kari", age: 42, city: "Oslo" };
write(JSON.stringify(Object.keys(person)));
/* Expected output: ["name","age","city"] */
write("\n");
write(Object.keys(person).length); // 3 Output
The JS code above produces the output shown below:["name","age","city"]
3