Object.getOwnPropertyNames()
Returns an array of all own string-keyed property names, including non-enumerable ones.
Syntax
Object.getOwnPropertyNames(obj) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | The object whose own property names are returned. |
Returns
Array — An array of all own string property names (enumerable or not).
Examples
const o = {};
Object.defineProperty(o, 'hidden', { value: 1, enumerable: false });
console.log(Object.getOwnPropertyNames(o));
Output
[ 'hidden' ]
console.log(Object.getOwnPropertyNames([1, 2]));
Output
[ '0', '1', 'length' ]
Notes
Unlike `Object.keys`, this includes non-enumerable properties. Symbol keys are
excluded - use `Object.getOwnPropertySymbols` for those.
Browser & runtime support
| Environment | Since version |
|---|---|
| chrome | 5 |
| firefox | 4 |
| safari | 5 |
| edge | 12 |
| node | 0.10 |