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

    Function countSubstring

    • Counts how many times a substring occurs within a string.

      Parameters

      • str: string

        The input string.

      • sub: string

        The substring to count.

      Returns number

      Number of times sub occurs in str.

      • Overlapping substrings are not double-counted.
      • Returns 0 if the substring is not found.
      countSubstring("lololol", "lo"); // 3
      countSubstring("aaaaa", "a"); // 5
      countSubstring("hello", "z"); // 0