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

    Function longestWordLength

    • Finds the length of the longest word in a string.

      Parameters

      • str: string

        The input string.

      Returns number

      Length of the longest word.

      • Words are split by whitespace (/\s+/).
      • Symbols (punctuation, special chars) are removed using stripSymbols.
      • Returns 0 if the string is empty or contains no words.
      longestWordLength("js utils kit");              // 5
      longestWordLength("short longerword mid"); // 10
      longestWordLength("hello"); // 5
      longestWordLength(""); // 0