Socket
Socket
Sign inDemoInstall

@gaiama/array-to-map

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @gaiama/array-to-map

Convert an array of objects to ES6 Map indexed by id or custom property


Version published
Maintainers
1
Install size
4.59 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 19 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc