var arr = ["1","2","3"];
var str = ["1","3"];
var s = arrSubtraction(arr,str)
console.log(s)
// 数组相减
function arrSubtraction(a, b) {
if (!a || !b || Object.prototype.toString.call(a) !== '[object Array]' || Object.prototype.toString.call(b) !==
'[object Array]') {
throw new Error('arrSubtraction(): Wrong Param Type')
}
for (var i = 0, len = b.length; i < len; i++) {
for (var j = 0, jen = a.length; j < jen; j++) {
if (a[j] === b[i]) {
a.splice(j, 1);
j--
}
}
}
return a
}
记一次js中数组相减的方法
最新推荐文章于 2023-09-22 18:24:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)