Something like indexOf, except I need to find all indexes. If there's .indexOf and ,lastIndexOf , shouldn't there be a function to get all index occurences? I couldn't find.
Note that the string is very large, about 1MB in size, so I would need the fastest solution.
To clarify, I need to get all positions of where a substring occurs in a string.
E.g.
var str = "foo bar foo bar"; //the real string is 1MB
var indexes = str.indexOfAll('foo'); //the function I need
console.log(indexes); //should print [0,8];
One thing that comes to mind is to use indexOf in a recurring loop, finds the first word, cut the string at the index, then use indexOf again and so on until it finds nothing. I'm not sure about performance (cutting and re-creating large strings).