惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
T
Threat Research - Cisco Blogs
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Security Latest
Security Latest
Spread Privacy
Spread Privacy
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
U
Unit 42
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Scott Helme
Scott Helme
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
爱范儿
爱范儿
S
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Latest news
Latest news
GbyAI
GbyAI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
PCI Perspectives
PCI Perspectives
Jina AI
Jina AI
AI
AI
NISL@THU
NISL@THU
I
Intezer
G
GRAHAM CLULEY
B
Blog
S
Secure Thoughts
IT之家
IT之家
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - howhy

html 元素包含关系 this 指向 空对象 Object.keys for ...in Reflect.ownKeys ...区别 逻辑运算符和空值运算符 运算符优先级 js 类型显式转换 js 高级函数 js 方法重载 fetch timeout js 任务顺序执行 暂停 js 并发任务 js 动态拦截属性 js 通用动画 js groupby js 防抖和节流 实现 instanceof 操作符 js 单例模式 js 数组去重和扁平方法 js 继承方法 js new的过程实现 js deepCopy js '=='的隐性类型转换规则
判断两个对象是否相同
howhy · 2026-01-20 · via 博客园 - howhy
const obj=[
    {a:1,b:2},
    {b:2,a:1},
    {a:1,b:2},
    {a:3,b:{c:11,d:4}},
    {a:3,b:{d:4,c:1}}
]

const newArr=[...obj];
function isObject(obj){
    return obj!==null && typeof obj==='object';
}
function objIsEqual(obj1,obj2){
    if(!isObject(obj1) || !isObject(obj2)){
        return Object.is(obj1,obj2);
    }
    if(obj1===obj2){
        return true;
    }
    const keys1=Object.keys(obj1);
    const keys2=Object.keys(obj2);
    if(keys1.length!==keys2.length){
        return false;
    }
    for(let key of keys1){
        if(!keys2.includes(key)){
            return false;
        }
        const res=objIsEqual(obj1[key],obj2[key]);
        if(!res){
            return false;
        }
    }
    return true;
}
for(let i=0;i<obj.length;i++){
    for(let j=i+1;j<newArr.length;j++){
        //if(JSON.stringify(obj[i])===JSON.stringify(newArr[j])){
            if(objIsEqual(obj[i],newArr[j])){
            newArr.splice(i,1);
            j--;
        }
    }
}

console.log(newArr)