JS Utils Kit - v0.5.1
    Preparing search index...

    Function longestWord

    • Finds the longest word(s) in a string.

      Parameters

      • str: string

        The input string.

      Returns string | string[]

      The longest word as a string, or an array of tied words.

      • If only one longest word exists, returns it as a string.
      • If multiple longest words have the same length, returns them as an array.
      • Returns an empty string if there are no words.
      longestWord("js utils kit");              // "utils"
      longestWord("short longerword mid"); // "longerword"
      longestWord("hello"); // "hello"
      longestWord(""); // ""