Created
July 12, 2023 21:24
-
-
Save andresgcarmona/f5bb4a11f85864672b888ab21ae6949e to your computer and use it in GitHub Desktop.
Object properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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