Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array/uniquify-by-key"

Index

Functions

Functions

uniquifyByKey

  • uniquifyByKey<T, P>(array: T[], key: P): T[]
  • Removes objects from the array which the value of its specifed key included before by another


    Example:

    import { uniquifyByKey } "@thalesrc/js-utils/array";
    
    const array = [{a: 1}, {a: 1}, {a: 2}, {a: 3}, {a: 3}, {a: 4}];
    
    uniquifyByKey(array, 'a'); // [{a: 1}, {a: 2}, {a: 3}, {a: 4}]

    Prototype Example:

    import "@thalesrc/js-utils/array/proto/uniquify-by-key";
    
    const array = [{a: 1}, {a: 1}, {a: 2}, {a: 3}, {a: 3}, {a: 4}];
    
    array.uniquifyByKey('a'); // [{a: 1}, {a: 2}, {a: 3}, {a: 4}]

    Type parameters

    • T: Object

    • P: keyof T

    Parameters

    • array: T[]

      Collection of the objects

    • key: P

      Key to search the value on

    Returns T[]

    The new uniquified array

Generated using TypeDoc