返回指定字符串的对应的所有位置

<html>
<head>
<title>返回指定字符串的对应的所有位置</title>
</head>
<body>
<script language="javascript">
 var stringValue = "Lorem, ipsum, dolor sit amet, consectetur ,adipisicing elit,";
 var positions = new Array();
 var pos = stringValue.indexOf(",");

 while (pos > -1) {
  positions.push(pos);
  pos = stringValue.indexOf(",", pos + 1);
 }
alert(positions); //"3,24,32,35,52"

</script>
</body>
</html>

你可能感兴趣的:(返回指定字符串的对应的所有位置)