Skip to content

Instantly share code, notes, and snippets.

@robin-drexler
Created October 28, 2012 22:23
Show Gist options
  • Save robin-drexler/3970174 to your computer and use it in GitHub Desktop.
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
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