JavaScript Object.getOwnPropertyNames()

Definition and Usage

Object.getOwnPropertyNames() The method returns an array containing all property names of the object.

Object.getOwnPropertyNames() The method does not change the original object.

Related Methods:

Object.defineProperty() Add or modify properties.

Object.defineProperties() Add or modify multiple properties.

Object.getOwnPropertyNames() Return all property names of the object.

Object.getOwnPropertyDescriptor() Return the descriptor of the property.

Object.getOwnPropertyDescriptors() Return the descriptors of all properties of the object.

Instance

// Create an object
const person = {
  firstName: "Bill",
  lastName: "Gates",
  age: 50,
  eyeColor: "blue"
};
// Get all property names
let props = Object.getOwnPropertyNames(person);

Try it Yourself

Syntax

Object.getOwnPropertyNames(object)

Parameter

Parameter Description
object Required. Target object.

Return Value

Type Description
Array Array containing all property names of the object.

Browser Support

Object.getOwnPropertyNames() Is ECMAScript5 (ES5) feature.

Since July 2013, all modern browsers fully support ES5 (JavaScript 2009):

Chrome Edge Firefox Safari Opera
Chrome 23 IE/Edge 11 Firefox 21 Safari 6 Opera 15
September 2012 September 2012 April 2013 July 2012 July 2013