Kitto
    Preparing search index...
    • Finds the index of an object in an array that contains a specific key-value pair.

      Type Parameters

      • T extends Record<string | number, unknown>

      Parameters

      • arr: T[]

        The array of objects to search through

      • key: keyof T

        The key to match in the objects

      • value: T[keyof T]

        The value associated with the key to match

      Returns number

      The index of the object that matches the key-value pair. Returns -1 if no match is found

      This function is part of the array utilities module.

      2.0.0

      const data = [
      { id: 1, name: 'John' },
      { id: 2, name: 'Jane' },
      { id: 3, name: 'Joe' }
      ];

      const result_index = find_index(data, 'name', 'Jane');
      console.log(result_index); // 1