Options
All
  • Public
  • Public/Protected
  • All
Menu

Module array/indexBy

Index

References

Interfaces

Type aliases

Functions

References

Renames and re-exports indexBy

Type aliases

Pred<T>: (v: T, index: number, arr: ArrayLike<T>) => string

Type parameters

  • T

Type declaration

    • (v: T, index: number, arr: ArrayLike<T>): string
    • Parameters

      • v: T
      • index: number
      • arr: ArrayLike<T>

      Returns string

Functions

  • indexBy<T>(fn: Pred<T>, list: ArrayLike<T>): Record<string, T>
  • indexBy<T>(fn: Pred<T>): (list: ArrayLike<T>) => Record<string, T>
  • 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.

    example
     var list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
    indexBy(x => x.id, list);
    //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}

    Type parameters

    • T

    Parameters

    • fn: Pred<T>

      Function :: a -> String

    • list: ArrayLike<T>

    Returns Record<string, T>

    An object indexing each array element by the given property.

  • 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.

    example
     var list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
    indexBy(x => x.id, list);
    //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}

    Type parameters

    • T

    Parameters

    • fn: Pred<T>

      Function :: a -> String

    Returns (list: ArrayLike<T>) => Record<string, T>

    An object indexing each array element by the given property.

      • (list: ArrayLike<T>): Record<string, T>
      • Parameters

        • list: ArrayLike<T>

        Returns Record<string, T>

Generated using TypeDoc