首页 > 编程语言 > 详细

查询字符串中某个字符出现的位置数组

时间:2017-05-18 09:33:37      阅读:333      评论:0      收藏:0      [点我收藏+]
<!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>

 

查询字符串中某个字符出现的位置数组

原文:http://www.cnblogs.com/vscss/p/6871654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!