ts-utils
    Preparing search index...

    Function countOccurences

    • Counts the number of times a substring appears in a string. The search is case-sensitive and returns exact matches only.

      Parameters

      • string: string

        The string to search in

      • subString: string

        The substring to search for

      Returns number

      The number of occurrences of the substring in the string

      const lyrics = 'Baby shark, doo doo doo. Baby shark!';
      countOccurences(lyrics, 'doo') // => 3
      countOccurences(lyrics, 'shark') // => 2
      countOccurences(lyrics, 'shark,') // => 1
      countOccurences(lyrics, 'shark!') // => 1