查詢字符串中某個字符出現的位置數組
阿新 • • 發佈:2017-05-18
meta bsp scrip jquery dsa ans tex com lang
<!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>
查詢字符串中某個字符出現的位置數組