<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <script type="text/javascript"> $(function(){ var str = "bdsajsbvfcsddansfkjanhfhbfshdabajh"; var arr = []; var pos = str.indexOf("a"); while(pos>-1){ arr.push(pos); pos = str.indexOf("a",pos+1); }; console.log(str); console.log(arr); }); </script> </body> </html>