loash html js 原始demo


<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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值