index-by

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
2 KB
Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key.
1 contributor
Install index-by as a package?
Copied
npm i @bit/justin-capalbo.ramda.index-by
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
indexBy (
fn:Function,
array:Array
) : Object

Given a function that generates a key, turns a list of objects into an object indexing the objects by the given key. Note that if multiple objects generate the same value for the indexing key only the last value will be included in the generated object.

Acts as a transducer if a transformer is given in list position.

Example
const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
     R.indexBy(R.prop('id'), list);
     //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
Arguments
fn: Function

Function :: a -> String

array: Array

The array of objects to index

Returns
Object

An object indexing each array element by the given property.

Help and resources