Getting the object properties
Getting the property names of an object: getOwnPropertyNames()
The getOwnPropertyNames()
method is a built-in JavaScript function that returns an array of all non-inherited, enumerable properties of an object. These properties are the objectβs own properties, which have been defined directly on the object, and are not inherited from its prototype chain.
The getOwnPropertyNames()
method is useful when you need to obtain a list of an objectβs own properties for various purposes, such as serialization, copying, or enumeration.
Example
Hereβs an example demonstrating the use of getOwnPropertyNames()
to retrieve all the own property names: