Answers for "js return indicie of string of ceritn sub string"

0

js return indicie of string of ceritn sub string

function getIndicesOf(searchStr, str, caseSensitive) {
    var searchStrLen = searchStr.length;
    if (searchStrLen == 0) {
        return [];
    }
    var startIndex = 0, index, indices = [];
    if (!caseSensitive) {
        str = str.toLowerCase();
        searchStr = searchStr.toLowerCase();
    }
    while ((index = str.indexOf(searchStr, startIndex)) > -1) {
        indices.push(index);
        startIndex = index + searchStrLen;
    }
    return indices;
}
Posted by: Guest on April-01-2021

Code answers related to "js return indicie of string of ceritn sub string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language