tohash
v1.0.2
Published
Array to hash by key
Downloads
57
Readme
toHash
Turn your list of objects into a key:value hash based on key
const list = [
{
id: 1,
name: 'Mike'
},
{
id: 2,
name: 'Nick'
},
{
id: 3,
name: 'Brian'
},
{
id: 4,
name: 'Jake'
}
]
toHash(list, 'name') // default key is `id`
/*
{ 'Mike': { id: 1, name: 'Mike' },
'Nick': { id: 2, name: 'Nick' },
'Brian': { id: 3, name: 'Brian' },
'Jake': { id: 4, name: 'Jake' } }
*/