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

    Function countChars

    • Counts characters in a string.

      Parameters

      • str: string

        The input string.

      • Optionalchar: string

        Optional character to count.

      Returns number

      Number of characters or character occurrences.

      • If char is provided, only that character’s occurrences are counted.
      • If char is omitted, the function counts the number of substrings returned by splitString (similar to a word count).
      countChars("banana");       // 6
      countChars("banana", "a"); // 3
      countChars("banana", "n"); // 2