The object whose enumerable and non-enumerable properties are to be returned
An array of strings that correspond to the properties found directly in the given object
objGetOwnPropertyNames({ a: 1, b: 2 }); // ['a', 'b']
// Array properties include indices and 'length'
objGetOwnPropertyNames(['a', 'b']); // ['0', '1', 'length']
// Non-enumerable properties are included
const obj = Object.create({}, {
hidden: { value: 'secret', enumerable: false },
visible: { value: 'public', enumerable: true }
});
objGetOwnPropertyNames(obj); // ['hidden', 'visible']
The objGetOwnPropertyNames() method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly in a given object.