Skip to content

Repository files navigation

array-to-map

CircleCInpm version

Converting an array into a Map.

constmap=arrayToMap([{id: 'a',value: 1},{id: 'b',value: 2},{id: 'c',value: 3},]);console.log(map);/*{ {0 => { id: 'a', value: 1 }} {1 => { id: 'b', value: 2 }} {2 => { id: 'c', value: 3 }}}*/

You can decide how the keys are created:

constmap=arrayToMap([{id: 'a',value: 1},{id: 'b',value: 2},{id: 'c',value: 3},],item=>item.id);console.log(map);/*{ {'a' => { id: 'a', value: 1 }} {'b' => { id: 'b', value: 2 }} {'c' => { id: 'c', value: 3 }}}*/

License

MIT

About

Utility for generalized mapping of an array to a map

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages