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

    Function shortestWord

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

      Parameters

      • str: string

        The input string.

      Returns string | string[]

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

      • If only one shortest word exists, returns it as a string.
      • If multiple shortest words have the same length, returns them as an array.
      • Returns an empty string if there are no words.
      shortestWord("js utils kit"); // "js"
      shortestWord("one three five"); // "one"
      shortestWord("a ab abc abcd"); // "a"
      shortestWord(""); // ""