码迷,mamicode.com
首页 > 编程语言 > 详细

排除数组重复--javascript

时间:2014-11-02 13:38:49      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:io   ar   java   for   sp   on   log   cti   html   

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>排除数组重复</title>
</head>
<body>
<script>
    Array.prototype.checkRepeat=function(){
        var checkR=[];
        var len=this.length;
//        for(var i=0;i<len;i++){
//            for(var j=-1;j<checkR.length;j++){
//                if(this[i]==this[j]){
//                    break;
//                }else if(j==checkR.length-1){
//                    checkR.push(this[i]);
//                }
//            }
//
//        }
        for(var i=0;i<len;i++){
            for(var j=i+1;j<len;j++){
                if(this[i]==this[j]){
                    this.splice(j,1);//splice删除某个片段
                }
            }
        }

    }
    var show=[0,2,5,6,4,0,4,6,2,3]
    show.checkRepeat();
    console.log(show)
</script>

</body>
</html>

排除数组重复--javascript

标签:io   ar   java   for   sp   on   log   cti   html   

原文地址:http://www.cnblogs.com/puying2014/p/4068974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!