@gaiama/array-to-map

1.0.8 • Public • Published

array-to-map All Contributors npm version Build Status

Install

$ yarn add @gaiama/array-to-map
or
$ npm install @gaiama/array-to-map

Usage

const arrayToMap = require('array-to-map');
const array = [
  { id: 'first', title: 'The first item' },
  { id: 'second', title: 'The second item' },
]
arrayToMap(array);
//=> { first: { id: 'first', title: 'The first item' }, second: { id: 'second', title: 'The second item' } }

const array = [
  { slug: 'the-first-item', title: 'The first item' },
  { slug: 'the-second-item', title: 'The second item' },
]
arrayToMap(array, 'slug');
//=> { 'the-first-item': { slug: 'the-first-item', title: 'The first item' }, 'the-second-item': { slug: 'the-second-item', title: 'The second item' } }

API

arrayToMap(input, property)

input

Type: array

Array of objects

property

Type: string
Default: id

If your objects don't contain an id property or you want to map them to a different key specify as second argument

Contributors

Thanks goes to these wonderful people (emoji key):


Valentin Bucur

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © GaiAma

Package Sidebar

Install

npm i @gaiama/array-to-map

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

4.7 kB

Total Files

7

Last publish

Collaborators

  • canrau