Object

Object.getOwnPropertyNames

Returns an array of all properties (including non-enumerable) found directly in a given object

Syntax

JavaScript
Object.getOwnPropertyNames(obj)

Parameters

ParameterTypeDescription
objobjectThe object whose property names are to be returned

Return Value

An array of strings corresponding to the properties

Examples

Basic Usage
const obj = { a: 1, b: 2 };
console.log(Object.getOwnPropertyNames(obj)); // ['a', 'b']
Practical Example
const arr = [1, 2, 3];
console.log(Object.getOwnPropertyNames(arr)); // ['0', '1', '2', 'length']
Advanced Usage
const obj: Record<string, unknown> = {};
Object.defineProperty(obj, 'hidden', { value: 42, enumerable: false });
console.log(Object.keys(obj)); // []
console.log(Object.getOwnPropertyNames(obj)); // ['hidden']

Understanding Object.getOwnPropertyNames

The Object.getOwnPropertyNames method in JavaScript returns an array of all properties (including non-enumerable) found directly in a given object. It belongs to the Object object and is one of the most widely used methods for working with object values in modern JavaScript and TypeScript applications.

The method signature is Object.getOwnPropertyNames(obj). It accepts 1 parameter: obj. When called, it returns an array of strings corresponding to the properties. Understanding when and how to use getOwnPropertyNames() helps you write more expressive, readable code.

Common use cases for Object.getOwnPropertyNames include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like object-keys, object-getownpropertysymbols, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Object.getOwnPropertyNames is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Object Methods

Other methods in the Object object

Related Tools

More Object Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.