Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/get-own-enumerable-keys
Like Object.keys() but also includes symbols
https://github.com/sindresorhus/get-own-enumerable-keys
Last synced: 17 days ago
JSON representation
Like Object.keys() but also includes symbols
- Host: GitHub
- URL: https://github.com/sindresorhus/get-own-enumerable-keys
- Owner: sindresorhus
- License: mit
- Created: 2023-01-16T02:35:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-18T12:34:10.000Z (about 2 years ago)
- Last Synced: 2025-02-01T18:27:40.885Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 22
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# get-own-enumerable-keys
> Like [`Object.keys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) but also includes [symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)
`Object.keys()` returns the own enumerable keys of an object except symbols (for legacy reasons). This package includes symbols too.
Use [`Reflect.ownKeys()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) if you also want non-enumerable keys.
## Install
```sh
npm install get-own-enumerable-keys
```## Usage
```js
import getOwnEnumerableKeys from 'get-own-enumerable-keys';const symbol = Symbol('x');
const object = {
foo: true,
[symbol]: true,
};Object.keys(object);
// ['foo']getOwnEnumerableKeys(object);
//=> ['foo', Symbol('x')]
```