TS-Scribe - v0.6.2
    Preparing search index...

    Function pluckArray

    • Extracts the values of a specific key from an array of objects.

      This function maps over an array of objects and returns a new array containing the values of the specified key from each object.

      Type Parameters

      • T
      • K extends string | number | symbol

      Parameters

      • array: T[]

        The array of objects to pluck values from.

      • key: K

        The key whose values are to be extracted.

      Returns T[K][]

      An array of values for the specified key from each object in the array.

      const users = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
      const names = pluckArray(users, 'name');
      console.log(names); // Output: ['Alice', 'Bob']