<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组去重</title>
    <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
    <!-- 
    注释: 

    -->
</head>
<body>


<script>
    var a = [0,1,2,2,3,2,5];
    //var c = [0,1,2,2,3,5,3,4,656,42,14,32];
    var m = {};   //先定义个对象
    for(var i = 0; i<a.length; i++){
        
        m[a[i]] = "";   //mm=a[i]取到的是0,1,2,2,3,2,5,对象属性不可以重名,来去除重名

                        //m[mm]=""用来站位,m[0]="",m[1]="",m[2]="",m[2]="",m[3]=""m[2]="",m[5]="", 

                         //m = [,,,,]

    }

    console.log(m.valueOf());  //只输出m中的指针
   
   var h = [];

   for(a in m){
           h.push(a);   //把m通过a放入到h数组中
   }
  
  alert(h);

</script>    
</body>
</html>

 

给心灵一个纯净空间,让思想,情感,飞扬!