代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function repEat(arr) {
var emptyArr = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j] && emptyArr.indexOf(arr[j]) === -1) {
emptyArr.push(arr[i]);
}
}
}
return emptyArr;
}
var newArr = [1, 2, 4, 4, 3, 3, 1, 5, 3];
console.log(repEat(newArr));
</script>
</body>
</html>
运行结果