1.0.8 • Published 6 years ago

@gaiama/array-to-map v1.0.8

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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