JS Utils Kit
    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, counts total characters in the string.
      • All characters are included in the count:
        • spaces
        • tabs (\t)
        • newlines (\n)
        • unicode characters (emoji, symbols, etc.)
      • Internally uses splitString.
      countChars("banana");       // 6
      countChars("banana", "a"); // 3
      countChars("banana", "n"); // 2