Object.getOwnPropertyNames()
Example
// Create an Object
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
// Get Properties
let props = Object.getOwnPropertyNames(person);
Try it Yourself »
Description
The Object.getOwnPropertyNames()
method returns an array with the properties of an object.
The Object.getOwnPropertyNames()
method does not change the original object.
Related Methods:
Object.defineProperty() adds or changes one property.
Object.defineProperties() adds or changes many properties.
Object.getOwnPropertyNames() returns the property names of an object.
Object.getOwnPropertyDescriptor() returns the descriptor of a property.
Object.getOwnPropertyDescriptors() returns the descriptors of all properties.
Syntax
Object.getOwnPropertyNames(object)
Parameters
Parameter | Description |
object | Required. An iterable object. |
Return Value
Type | Description |
Array | An array containing the properties of the object. |
Browser Support
Object.getOwnPropertyNames()
is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) is fully supported in all modern browsers since July 2013:
Chrome 23 |
IE/Edge 11 |
Firefox 21 |
Safari 6 |
Opera 15 |
Sep 2012 | Sep 2012 | Apr 2013 | Jul 2012 | Jul 2013 |