Skip to content

Instantly share code, notes, and snippets.

@andresgcarmona
Created July 12, 2023 21:24
Show Gist options
  • Save andresgcarmona/f5bb4a11f85864672b888ab21ae6949e to your computer and use it in GitHub Desktop.
Save andresgcarmona/f5bb4a11f85864672b888ab21ae6949e to your computer and use it in GitHub Desktop.
Object properties
const obj = {
[Symbol('my_key')] : 1,
enum : 2,
nonEnum : 3
};
Object.defineProperty(obj, 'nonEnum', { enumerable: false }); // Making 'nonEnum' as not enumerable.
// Ignores symbol-valued property keys:
> Object.getOwnPropertyNames(obj)
['enum', 'nonEnum']
// Ignores string-valued property keys:
> Object.getOwnPropertySymbols(obj)
[Symbol(my_key)]
// Considers all kinds of keys:
> Reflect.ownKeys(obj)
[Symbol(my_key),'enum', 'nonEnum']
// Only considers enumerable property keys that are strings:
> Object.keys(obj)
['enum']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment