<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script>
//indexof的使用如果要检索的字符串值没有出现,则该方法返回 -1。
var arr1 = [1, 2, 2, 3, 3, 3, 3, 4, 4, 5];
var newArr = [];
function distinct(arr) {
// 函数主体
for (var i = 0; i < arr1.length; i++) {
if (newArr.indexOf(arr[i]) === -1) {
newArr.push(arr[i]);
}
}
}
distinct(arr1); // 输出[1,2,3,4,5]
console.log(newArr);
</script>
</head>
<body></body>
</html>