Simply take two arrays and find out the different items

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script>
	// var a = {name: 'fx', age: '18'}
	// var b = {name: 'fx', age: '33', sex: 'boy'}

	let a = [1, 2, 3, 4, 7, {a: 1}]
	let b = [1, 2, 3, 5, 4, 6, {a: 2}]
	let c = [...a, ...b]
	let d = new Set(c)
	let e = Array.from(d)
	console.log(e)
	let f = [...e.filter(_ => !a.includes(_)), ...e.filter(_ => !b.includes(_))]
	let g = [...e.filter(_ => a.includes(_)&&b.includes(_))]
	
	console.log('两个数组找出不相同的项:', f);
	console.log('两个数组找出其中相同的项:', g);
</script>
</body>
</html>

 

Guess you like

Origin blog.csdn.net/weixin_40013817/article/details/113618853
Recommended