<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="text" value="" oninput="change" />
<script>
let a = [1,2,3,4];
let b = [1,4,5,6,7,8];
let c = b.filter(item => !a.includes(item))
console.log('a', a) // [1,2,3,4]
console.log('b', b) // [1,4,5,6,7,8]
console.log('c', c) // [5,6,7,8];
</script>
</body>
</html>
这个博客展示了如何使用JavaScript进行数组过滤操作。通过`filter()`方法,从数组`b`中筛选出不在数组`a`中的元素,得到两数组的差集`c`。示例代码中,变量`a`包含[1,2,3,4],`b`包含[1,4,5,6,7,8],经过过滤操作,`c`变为[5,6,7,8]。这是一段关于JavaScript数组操作的基础教程。
1350

被折叠的 条评论
为什么被折叠?



