<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh" dir="ltr">标签:++,差集,JS,flag,arr3,arr2,arr1,var From: https://blog.51cto.com/u_21817/6066913
<script type="text/javascript">
var arr1 = [1,3,4,5,6,7,8];
var arr2 = [1,2,3,4];
var arr3 = new Array();
function test(){
for(var i=0; i < arr1.length; i++){
var flag = true;
for(var j=0; j < arr2.length; j++){
if(arr1[i] == arr2[j])
flag = false;
}
if(flag)
arr3.push(arr1[i]);
}
alert("差集:"+arr3.toString());
}
</script>
<body>
<a href="" οnclick="test()">test</a>
</body>
</html>