<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body> </body>
</html>
<script type="text/javascript">
var arr=[1,2,2,3,4,1,2,3,4,5,222,5,6,7,6,7,6,7,8,9,111]
var re=[];
var json={};
for (var i = 0; i < arr.length; i++) {
if(!json[arr[i]]){
re.push(arr[i])
json[arr[i]]=true;
}
};
console.log(re) var arr2=[1,2,2,3,4,1,2,3,4,5,222,5,6,7,6,7,6,7,8,9,111]
arr2.sort();
var rr=[];
for (var i = 0; i < arr2.length; i++) {
if (rr[rr.length-1]!=arr2[i]) {
rr.push(arr2[i]);
};
};
console.log(rr)
</script>
俩方法,都是网上找的,不过已经琢磨清楚了,这样算是自己的了吧