array-to-map

Light utility to convert your [keys] to a {key:key} map

MIT 4 个版本
安装
npm install array-to-map
yarn add array-to-map
pnpm add array-to-map
bun add array-to-map
README

array-to-map

Light utility to convert your [keys] to a {key:key} map

Usage

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,

var getMap = require('array-to-map');

var map = getMap([1, 2, "abc", {key:123}, function () {}]);
// Still {'1':1, '2':2, 'abc':'abc'}
版本列表
1.0.3 2015-11-05
1.0.2 2015-03-18
1.0.1 2015-03-18
1.0.0 2015-03-18