0.1.3 • Published 6 years ago

@nombienombie/array-to-hash v0.1.3

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

array-to-hash

A simple function for reducing an array of data into an object.

Why this is useful?

Arrays can be slow for searching if you do not know the index of the item you require. Objetcs can be much quicker with larger data sets as we can use the key, allowing us to get the value as fast as it can be retrieved from memory.

Example:

const arrayToHash = require('@nombienombie/array-to-hash');

const users = [{ id: 1, name: 'Foo' }, { id: 2, name: 'Bar' }, { id: 3, name: 'Boo' }];

const userHash = arrayToHash(users);

console.log(userHash);
/*
{
    1: {id: 1, name: 'Foo'},
    2: {id: 2, name: 'Bar'},
    3: {id: 3, name: 'Boo'},
}
*/

Usage

$ npm install --save @nombienombie/array-to-hash
0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago