function locations(substring,string){ var a=[],i=-1; while((i=string.indexOf(substring,i+1)) >= 0) a.push(i); return a; } console.log(locations("s","scissors")); //-> [0, 3, 4, 7]