["Getting all occurrences of substring within a string","<h4>Usage<\/h4>\r\nThe Javascript method indexOf() will return the index location of a substring within a string.\u00a0 However, it will by default only return an integer with the first occurring location of that substring.\u00a0 The following function will return all indices where the substring occurs in an array.  When no occurrences of the substring are present, an empty array is returned.\r\n<pre>\r\nfunction getIndicesOf(searchStr, str, caseSensitive) {\r\n    var searchStrLen = searchStr.length;\r\n    if (searchStrLen == 0) {\r\n        return [];\r\n    }\r\n    var startIndex = 0, index, indices = [];\r\n    if (!caseSensitive) {\r\n        str = str.toLowerCase();\r\n        searchStr = searchStr.toLowerCase();\r\n    }\r\n    while ((index = str.indexOf(searchStr, startIndex)) > -1) {\r\n        indices.push(index);\r\n        startIndex = index + searchStrLen;\r\n    }\r\n    return indices;\r\n}\r\n<\/pre>"]