<html>
<head>
<title>Lodash-Working Example</title>
<script type = "text/JavaScript" src = "https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>
<style>
div {
border: solid 1px #ccc;
padding:10px;
font-family: "Segoe UI",Arial,sans-serif;
width: 50%;
}
</style>
</head>
<body>
<div style = "font-size:25px" id = "list"></div>
<script type = "text/JavaScript">
// 去重
// const arr = [1, 1, 2, 3, 3, 4, 5];
// console.log(_.uniq(arr)); // [1, 2, 3, 4, 5]
// const _ = require('lodash');
// 两个包含对象的数组
// const array1 = [
// { id: 1, name: 'Alice' },
// { id: 2, name: 'Bob' },
// { id: 3, name: 'Charlie' },
// ];
// const array2 = [
// { id: 2, name: 'Bob' },
// { id: 3, name: 'Charlie' },
// { id: 4, name: 'David' },
// ];
// 自定义比较函数,用来比较两个对象是否相等
// function customComparison(obj1, obj2) {
// return obj1.id === obj2.id && obj1.name === obj2.name;
// }
// 使用 _.differenceWith 找出两个数组之间不同的对象
// const difference = _.differenceWith(array1, array2, customComparison);
// const a = !5
// const b = !!5
// console.log(!5)
const array1 = [
1, 2, 3, 4, 5
];
const array2 = [
1, 3, 2, 5, 4
];
console.log(_.isEqual(array1, array2))
// console.log(difference);
// 在这个示例中,我们首先定义了两个包含对象的数组 array1 和 array2,然后使用 differenceWith 函数来找出这两个数组之间不同的对象。customComparison 函数用于定义对象的相等性规则,它会根据对象的 id 和 name 属性来判断两个对象是否相等。difference 数组包含了两个数组之间不同的对象。
// 你可以根据实际的对象属性和比较规则来自定义 customComparison 函数,以满足你的需求。这个方法可以用于比较两个包含对象的数组并提取它们之间的不同项。
</script>
</body>
</html>
01-31