找出数组下标并返回下标数
代码演示:
<script>
var str = 'Hello world, Hello javascript.';
var newArr = getChar(str,'o');
(newArr);
function getChar(str,myChar) {
var arr = [];
var index = (myChar);
(index);
while (index != -1) {
index = (myChar,index + 1);
if(index != -1) {
(index);
}
}
return arr;
}
</script>
输出结果:
4,7,17