sheng-tool
    Preparing search index...

    Function getValueByAnotherValue

    • 在一个对象数组中,根据指定的 key 和 value,查找对应的元素(使用深比较,返回第一个), 并返回其 anotherKey 对应的值,如果没找到,则返回 undefined。

      Type Parameters

      • T

      Parameters

      • arr: T[]

        对象数组

      • key: keyof T

        要查找的指定的 key

      • value: any

        要查找的指定的 value

      • anotherKey: keyof T

        需要返回的值对应的 key

      Returns NonNullable<T>[keyof T] | undefined

      0.0.21

      getValueByAnotherValue([{ a: 1, b: 2 }, { a: 2, b: 3 }], 'a', 2, 'b')   // 3
      getValueByAnotherValue([{ a: 1, b: 2 }, { a: 2, b: 3 }], 'a', 3, 'b') // undefined