//需求:两个数组做比较,在ary01里把含有ary02的元素删掉,组成新的数组ary03
let ary01=[1,2,3,4,5] let ary02=[1,5] let ary03=[] for (var i = 0; i < ary01.length; i++) { for (var j = 0; j < ary02.length; j++) { if (ary01[i] == ary02[j]) { ary01[i] = ""; break; } } } console.log(ary01)//["",2,3,4,""] for (var i = 0; i < ary01.length; i++) { if (ary01[i] != "") { ary03.push(ary01[i]) } } console.log(ary03)//[2,3,4]