js数组去除重复对象元素

news/2024/7/19 14:22:54 标签: js
export function deleteRe(arr) {
    const temp = {},//用于id判断重复
    result = [];//最后的新数组
    //遍历c数组,将每个item.id在temp中是否存在值做判断,
    for(let i = 0, len = arr.length; i < len; i++) {
        const item = arr[i];
        if(!temp[item.name]){
            result.push(item);
            temp[item.name] = true
        }
    }
    return result;
}

http://www.niftyadmin.cn/n/740754.html

相关文章

vue 守卫

全局进入前守卫 router.beforeEach((to, from, next) > {// ... })局部守卫

laravel5.7中pc端二维码支付

生成订单日志&#xff0c;可创一张表&#xff0c;在生成二维码时创建记录&#xff0c;在用户离开支付二维码未支付时&#xff0c;将该条记录的其中标记错误的字段附上错误信息&#xff0c;若成功&#xff0c;则标记订单成功时间 准备工作: 安装 overtrue/laravel-wechat comp…

laravel5.7微信支付controller汇总

[主要为网上参考] <?php namespace App\Http\Controllers; use App\User; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Auth; use Il…

一行搞定php深度克隆

合并数组的方式实现 <?phppublic fucntion test(){$newArray array_merge(array(), $oldArray); } ?>

php数组去重后返回数组包对象给前端

// 二維數組去重 <?phppublic function test(){$arr array([id >1, name > wutongyue],[id >5, name > wutongyue],[id >2, name > wutongyue], [id >4, name > wutongyue], [id >3, name > lowingshan, title > hello world]);foreach…

爬虫入门指南:如何使用正则表达式进行数据提取和处理

文章目录 正则表达式正则表达式中常用的元字符和特殊序列案例 使用正则表达式提取数据案例存储数据到文件或数据库使用SQLite数据库存储数据的示例代码SQLite基本语法创建表格&#xff1a;插入数据&#xff1a;查询数据&#xff1a;更新数据&#xff1a;删除数据&#xff1a;条…

Mybatis.generator映射连接本地wamp的mysql数据库报错

很可能原因&#xff0c;jdbc版本6以上对连接的数据库serverTimezone有要求 解决方法一【推荐】&#xff1a;在数据库配置文件my.ini中的[mysqlId]下添加 default-time-zone8:00

uni-app将rpx转px

sizeDeal(size) {const info uni.getSystemInfoSync()this.scale 750 / info.windowWidth;// 分离字体大小和单位,rpx 转 pxlet s Number.isNaN(parseFloat(size)) ? 0 : parseFloat(size)let u size.toString().replace(/[0-9]/g, ).replace(-,)if (u rpx) {s / this.sc…