Skip to content

Utility for generalized mapping of an array to a map

License

Notifications You must be signed in to change notification settings

enkidevs/array-to-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

58e59df Β· Sep 20, 2021
Mar 30, 2020
Jan 14, 2019
Apr 7, 2020
Jan 14, 2019
Jan 14, 2019
Jan 14, 2019
Jan 14, 2019
Mar 14, 2020
Jan 14, 2019
Sep 20, 2021
Jul 5, 2021

Repository files navigation

array-to-map

CircleCI npm version

Converting an array into a Map.

const map = 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:

const map = 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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published