Object.getOwnPropertyNames()

The Object.getOwnPropertyNames() method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly upon a given object.

Syntax

Object.getOwnPropertyNames(obj)

Parameters

obj

The object whose enumerable and non-enumerable own properties are to be returned.

Return value

An array of strings that correspond to the properties found directly upon the given object.

Description

Object.getOwnPropertyNames() returns an array whose elements are strings corresponding to the enumerable and non-enumerable properties found directly upon obj. The ordering of the enumerable properties in the array is consistent with the ordering exposed by a for...in loop (or by Object.keys()) over the properties of the object. The ordering of the non-enumerable properties in the array, and among the enumerable properties, is not defined.

If you want only the enumerable properties, see Object.keys() or use a for...in loop (although note that this will return enumerable properties not only found directly upon that object but also along the prototype chain for the object unless the latter is filtered with hasOwnProperty()).

Get Non-Enumerable Only

This uses the Array.prototype.filter() function to remove the enumerable keys (obtained with Object.keys()) from a list of all keys (obtained with Object.getOwnPropertyNames()) leaving only the non-enumerable keys.