Why are two identical objects not equal to each other?

前端 未结 9 685
广开言路
广开言路 2020-11-22 05:43

Seems like the following code should return a true, but it returns false.

var a = {};
var b = {};

console.log(a==b); //returns false
console.log(a===b); //         


        
9条回答
  •  -上瘾入骨i
    2020-11-22 05:55

    use JSON.stringify(objname);
    
    var a = {name : "name1"};
    var b = {name : "name1"};
    
    var c = JSON.stringify(a);
    var d = JSON.stringify(b);
    
    c==d;
    //true
    

提交回复
热议问题