JS 获得 str 中子字符串 subStr 出现的所有位置(返回 index 数组)

8 min read
export function getIndexes(str: string, subStr: string){
    let indexes  = [];
    let idx = str.indexOf(subStr);
    while(idx > -1){
        indexes.push(idx);
        idx = str.indexOf(subStr, idx+1);
    }
    return indexes;
}