Object.getOwnPropertyNames()
ES5+Returns an array of all properties found directly in a given object.
Syntax
Object.getOwnPropertyNames(obj)Parameters
obj Object The object whose enumerable and non-enumerable properties are to be returned
Return Value
Array
An array of strings corresponding to the properties
Examples
JavaScript
const obj = { a: 1, b: 2 };
Object.defineProperty(obj, 'c', { value: 3, enumerable: false });
console.log(Object.keys(obj));
console.log(Object.getOwnPropertyNames(obj)); Output:
// ['a', 'b']
['a', 'b', 'c']