JS去重-删除连续重复的值

function removeRepetition(str) {
                var result = "",
                    unStr;
                for(var i=0,len=str.length;i<len;i++){
                    //因为unStr始终是当前的str.charAt(i)的前一个字母   因为unStr的赋值unStr=str.charAt(i)是在上一轮循环完成的
                    //所以可以删除连续重复的地方
                    if(str.charAt(i)!==unStr){
                        unStr=str.charAt(i);
                        result+=unStr;
                        console.log(result);
                    }
                }
                return result;
            }
原文地址:https://www.cnblogs.com/cmy1996/p/9192553.html