Tweakr
    Preparing search index...

    Function wordCount

    • Counts the number of words in a string. Words are sequences of non-whitespace characters separated by spaces.

      Parameters

      • str: string

        The input string to count words from.

      Returns number

      The number of words in the string.

      1.1.0

      wordCount("Hello world!"); // 2
      wordCount(" This is a test. "); // 4
      wordCount(""); // 0