Index of Substrings

    0

    0

    Giovanny Gongora

    Codiga's TypeScript Recipes

    Finds all the indexes of a substring in a given string.

    const indexOfSubstrings = function* (str: string, searchValue: string) {
      let i: number = 0;
      while (true) {
        const r: number = str.indexOf(searchValue, i);
        if (r !== -1) {
          yield r;
          i = r + 1;
        } else return;
      }
    };
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.