账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue中 两个对象数组 去重, 把 不一样的 push到一个新数组里 怎么操作 小白求关爱
    22
    0
     let a = [
              {employeeId: "TAEP201903130011",itemId: "C001",targetValue: 999,thisDate: "2019-07-13"},
              {employeeId: "TAEP201903130011",itemId: "C002",targetValue: 887,thisDate: "2019-07-13"},
              {employeeId: "TAEP201903130011",itemId: "C003",targetValue: 777,thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026",itemId: "C001",targetValue: null,thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026",itemId: "C002",targetValue: null,thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026",itemId: "C003",targetValue: null,thisDate: "2019-07-13"}
            ]
    let b = [
              {employeeId: "TAEP201903130011", itemId: "C001", targetValue: 999,  thisDate: "2019-07-13"},
              {employeeId: "TAEP201903130011", itemId: "C002", targetValue: 887,  thisDate: "2019-07-13"},
              {employeeId: "TAEP201903130011", itemId: "C003", targetValue: 777,  thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026", itemId: "C001", targetValue: null, thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026", itemId: "C002", targetValue: "2",  thisDate: "2019-07-13"},
              {employeeId: "TAEP201905060026", itemId: "C003", targetValue: null, thisDate: "2019-07-13"}
            ]
    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • ┆щō夠làㄙ┆ 普通会员 1楼

      在 Vue 中,你可以使用 Array.prototype.filter() 方法来过滤数组并移除重复的元素。以下是一个示例:

      ```javascript var array1 = ['apple', 'banana', 'apple', 'orange', 'pear']; var array2 = ['apple', 'banana', 'pear', 'grape', 'orange'];

      var uniqueArray = array1.filter((item, index, self) => { return self.indexOf(item) === index; });

      console.log(uniqueArray); // 输出:['apple', 'banana', 'orange', 'pear'] ```

      在这个示例中,filter() 方法接受一个回调函数,该函数接受三个参数:要过滤的数组、当前迭代的索引和当前数组本身。在回调函数中,我们检查当前元素是否在 self.indexOf(item) 中。如果是,则说明这个元素在 self 中的索引不正确,需要将其从数组中移除。

      这个方法不会改变原始数组,而是创建一个新的数组,其中只包含原始数组中的唯一元素。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部