两个数组去重
let array1 = [1, 2, 3, 4, 5],
array2 = [2, 3, 4];
array2.map(value2 => {
let index = array1.indexOf(value2);
if (index != -1) {
array1.splice(index, 1);
}
})
console.log(array1, array2);
let array1 = [1, 2, 3, 4, 5],
array2 = [2, 3, 4];
array2.map(value2 => {
let index = array1.indexOf(value2);
if (index != -1) {
array1.splice(index, 1);
}
})
console.log(array1, array2);
展开
2
点赞
![[嘿哈]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_67.9ceed33.png)
![[偷笑]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_20.7a46372.png)
![[思考]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_15.f58c082.png)
![[害羞]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_7.eca1535.png)