<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript" charset="UTF-8">
var removal = function(arr){
    this.toObj = function(arr){
        var obj = {};
        for (var i =0,j=arr.length;i<j;i++) {
            obj[arr[i]] = true;
        }
        return obj;
    }
    this.toArr = function(obj){
        var newArr = [];
        for (var attr in obj) {
            if(obj.hasOwnProperty(attr)){
                newArr.push(attr);
            }
        }
        return newArr;
    }
} 
var arr = [1,2,3,3,4,4,5,10,9,9,5,3,2,1];
var fn = new removal();
alert(fn.toArr(fn.toObj(arr)));
</script>
</body>
</html>


官方公众号