Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "array/find-by-key"

Index

Functions

Functions

findByKey

  • findByKey<T, K>(array: T[], key: K, value: T[K]): T
  • Finds an object in an array by matching the value set on the key


    Example:

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

    Prototype Example:

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

    Type parameters

    • T

    • K: keyof T

    Parameters

    • array: T[]

      Collection of the objects

    • key: K

      Key to search the value on

    • value: T[K]

      Value to match for the key

    Returns T

    Found object or undefined

Generated using TypeDoc