var str = "I think of other ages that floated upon the stream of life and love and death";
var positions = [];
function searchSubStr(str, subStr){
var pos = str.indexOf(subStr);
while(pos>-1){
positions.push(pos);
pos = str.indexOf(subStr, pos+1);
}
}
searchSubStr(str,"o");
原文:https://blog.csdn.net/yeoman92/article/details/54949048