去掉和已有数据重复的数据And去掉自己本身重复数据

原本有数据,后添加的数据不能与原来数据有重复值。 

                
                const data: [] = result.data.content;// 从后端获取到的数据
                if( _this.notices.length > 0) {
                // 如果notices本来就有数据,则后面新进的数据要将与前面数据中重复的删掉
                    const validData = data.filter((collect) => _this.notices
                        .findIndex((coll) => coll.id === collect.id) < 0 )
                        // 过滤出与原来数据中不同的数据
                    if(validData.length <=0 ) {
                        console.info(‘没有数据啦!’)
                    } else {
                        _this.notices.push(...validData)
                        this.dataState = 2
                    }
                } else {
                    // 如果notices刚开始没有数据,则直接将data返回数据赋给他
                    _this.notices = data
                }

初始值中去掉重复数据

        function myFunction(item) {
            var numbers = [
                {id: 1, name: '陈黄平'},
                {id: 2, name: '平儿'},
                {id: 3, name: '黄黄'},
                {id: 4, name: '朱朱'},
                {id: 4, name: '喆喆'}
            ];
            let hash = {}
            var aa = numbers.reduce((total, item) => {
                console.log(!hash[item.id])
                if (!hash[item.id]) {
                    hash[item.id] = true
                    total.push(item)
                }
                return total
            }, [])
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值