Function occurrences

Count the number of occurrences of a substring in a string

occurrences("aaa", "a"); // 3
occurrences("aaaa", "aa", { overlap: false }); // 2
occurrences("aaaa", "aa", { overlap: true }); // 3
  • Parameters

    • string: string

      string to search in

    • search: string

      string to search for

    • Optionaloptions: OccurencesOptions = {}

      options

    Returns number