Created
October 28, 2012 22:23
-
-
Save robin-drexler/3970174 to your computer and use it in GitHub Desktop.
Returns the indexes within the string of the occurrences of the specified value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function indexesOf(source, searchTerm) { | |
var occurrences = [], | |
index = 0; | |
while (index = ~source.indexOf(searchTerm, index)) { | |
index = ~index; | |
occurrences.push(index); | |
index++; | |
} | |
return occurrences; | |
} | |
console.log(indexesOf("das ist toll und ist super und ist auch cool", "a")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment