https://github.com/ashubham/array-to-map
Light utility to convert your [keys] to a {key:key} map
https://github.com/ashubham/array-to-map
Last synced: 3 months ago
JSON representation
Light utility to convert your [keys] to a {key:key} map
- Host: GitHub
- URL: https://github.com/ashubham/array-to-map
- Owner: ashubham
- License: mit
- Created: 2015-03-18T00:29:47.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-05T03:42:54.000Z (about 10 years ago)
- Last Synced: 2025-03-23T19:18:43.683Z (10 months ago)
- Language: JavaScript
- Size: 152 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# array-to-map
Light utility to convert your [keys] to a {key:key} map
### Usage
```javascript
var getMap = require('array-to-map');
var map = getMap([1, 2, "abc"]);
// {'1':1, '2':2, 'abc':'abc'}
```
The best use case for this tool is when a conversion from an array to a map is needed for efficient membership checking.
### Gotchas
Unserializable elements like `objects` and `functions` are ignored by this tool.
So something like,
```javascript
var getMap = require('array-to-map');
var map = getMap([1, 2, "abc", {key:123}, function () {}]);
// Still {'1':1, '2':2, 'abc':'abc'}
```