<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var arr=[1,2,3,4,5,3,2,1]
function show(arr){
var json={};
var result=[];
for (var i = 0; i < arr.length; i++) {
//json.arr[i]) json.1 undefind
if(!json[ arr[i] ]){
result.push(arr[i]);
json[ arr[i]]=1;
}
};
return result;
}
console.log(show(arr))
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
var arr=[1,2,3,4,5,3,2,1]
function show(arr){
var json={};
var result=[];
for (var i = 0; i < arr.length; i++) {
//json.arr[i]) json.1 undefind
if(!json[ arr[i] ]){
result.push(arr[i]);
json[ arr[i]]=1;
}
};
return result;
}
console.log(show(arr))
</script>
</body>
</html>