common-utility-functions
    Preparing search index...

    Function filterStringArray

    • Filters an array of strings to include only those that contain the specified substring. Uses the native String.includes() method for case-sensitive substring matching.

      Parameters

      • array: string[]

        The array of strings to filter

      • filter: string

        The substring to search for within each string

      Returns string[]

      A new array containing only strings that include the filter substring

      const fruits = ['apple', 'banana', 'apricot', 'grape'];

      filterStringArray(fruits, 'ap'); // ['apple', 'apricot']
      filterStringArray(fruits, 'ban'); // ['banana']
      filterStringArray(fruits, 'xyz'); // []

      // Empty filter matches all strings
      filterStringArray(fruits, ''); // ['apple', 'banana', 'apricot', 'grape']

      // Case sensitive
      filterStringArray(['Hello', 'hello'], 'H'); // ['Hello']

      1.0.0