JavaScript Object.getOwnPropertyNames() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

Object.getOwnPropertyNames(obj) returns an array of all own string property names on obj. Non-enumerable names are included. Symbol keys are not.

Compare with Object.keys(), which returns only enumerable own string keys. Use getOwnPropertyNames when you need the complete string-key list.

Syntax

Call Object.getOwnPropertyNames() like this. Start with this line.

JavaScript
Object.getOwnPropertyNames(obj)
CallWhat it does
Object.getOwnPropertyNames(obj)Returns an array of every own string property name on obj.

Built into JavaScript. Call on Object — no import required.

Library declarations
JavaScript
Object.getOwnPropertyNames(obj)
JavaScript
getOwnPropertyNames(o: object): string[];

Parameters

ParameterDescription
objRequired. The object to inspect. Primitives are boxed first.

Return Value

Return ValueDescription
string[]An array of own string property names, including non-enumerable ones. Order matches the usual property order rules.

JavaScript Examples

Example 1 — Basic Use

List the own string names on a simple object.

JavaScript
var car = {
  brand: "Tesla",
  year: 2024
};

console.log(Object.getOwnPropertyNames(car));
Try It Yourself

How It Works

  1. Create an object Both brand and year are own string properties.
  2. List the names Object.getOwnPropertyNames(car) returns an array of those names.
  3. Same as keys here When every property is enumerable, the result matches Object.keys().

Example 2 — vs Object.keys()

See how non-enumerable properties appear in names but not in keys.

JavaScript
var data = { visible: 1 };
Object.defineProperty(data, "hidden", {
  value: 2,
  enumerable: false
});

console.log(Object.keys(data));
console.log(Object.getOwnPropertyNames(data));
Try It Yourself

How It Works

  1. Add a hidden key defineProperty creates hidden with enumerable: false.
  2. keys skips it Object.keys() only returns enumerable own string names.
  3. names includes it getOwnPropertyNames() returns both visible and hidden.

Example 3 — Array Length

Arrays have a non-enumerable length property that still shows up here.

JavaScript
var nums = [10, 20, 30];

console.log(Object.keys(nums));
console.log(Object.getOwnPropertyNames(nums));
Try It Yourself

How It Works

  1. Index keys Array indexes are string keys: "0", "1", "2".
  2. length is own length is an own property, but it is not enumerable.
  3. Names show length getOwnPropertyNames includes "length"; Object.keys does not.

Browser & Runtime Support

Object.getOwnPropertyNames() has been available since ES5. It is Baseline and safe everywhere modern code runs.

✓ Baseline · ES5

Object.getOwnPropertyNames()

Supported in all modern browsers and Node.js. No polyfill needed for current projects.

99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Object.getOwnPropertyNames Excellent

Bottom line: Use freely. Pair with Object.getOwnPropertySymbols() when you also need symbol keys.

Frequently Asked Questions

An array of all own string property names on the object, including non-enumerable ones. Symbol keys are not included.
Object.keys() returns only enumerable own string keys. getOwnPropertyNames() also includes non-enumerable string keys.
No. Only properties that belong directly to the object are listed.
No. Use Object.getOwnPropertySymbols() for symbol keys, or Reflect.ownKeys() for strings and symbols together.
JavaScript follows a defined property order (integer indexes first, then other string keys in creation order). Do not rely on custom sorting.

Next: getOwnPropertySymbols()

Find every own property whose key is a Symbol.

getOwnPropertySymbols() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful