o[s[i]]就是用来判断s[i]有没有出现过 所以取到一次后就把o[s[i]]
设成1
<script type="text/javascript">var a =["1","2","4","5"]
var b=["1","2","3"]
for(var i=0,len=b.lengthi<leni++){
if(a.indexOf(b[i])>=0){
for(var j=0,alen=a.lengthj<alenj++){
if(a[j]==b[i]){
delAElem(a,j)
}
}
}
}
alert(a)
function delAElem(array,num){
for(var i=num,len=a.lengthi<len-numi++){
array[i]=array[i+1]
}
a.length--
}
</script>
思路是先找到重复元素在a数据中的index,之后再将a数组元素向前移动,最后修改数组长度