标签:func var rip script === title 出现 log lang
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
//.封装函数, 在数组 arr 中,查找值与 item 相等的元素出现的所有位置.
//示例: console.log(findAllOccurrences([ ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘a‘, ‘b‘, ‘c‘ ], ‘a‘)); 返回结果: [0, 6];
function findAllOccurrences(arr, item){
var subArr = [];
for(var i = 0; i < arr.length; i++){
if(arr[i] === item){
subArr.push(i);
}
}
return subArr;
}
console.log(findAllOccurrences([ ‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘a‘, ‘b‘, ‘c‘ ], ‘a‘));// [0, 6];
</script>
</body>
</html>
.封装函数, 在数组 arr 中,查找值与 item 相等的元素出现的所有位置.
标签:func var rip script === title 出现 log lang
原文地址:https://www.cnblogs.com/yxs1530/p/10242458.html