Javascript 打字脚本和ExactEqual

Javascript 打字脚本和ExactEqual,javascript,typescript,Javascript,Typescript,如何以最简单的方式检查两个对象是否相等?我注意到没有类似的方法ExactEqual(),所以我想知道是否应该手动执行 谢谢你的帮助 没有这样的方法。看看这个链接,在那里讨论了它,并给出了最好的检查方法。这将适用于类型脚本和javascript。希望对你有帮助 引用该答案中最重要的部分: //“===” means that they are identical. //“==” means that they are equal in value. //( == ) //Each JavaScri

如何以最简单的方式检查两个对象是否相等?我注意到没有类似的方法
ExactEqual()
,所以我想知道是否应该手动执行


谢谢你的帮助

没有这样的方法。看看这个链接,在那里讨论了它,并给出了最好的检查方法。这将适用于类型脚本和javascript。希望对你有帮助

引用该答案中最重要的部分:

//“===” means that they are identical.
//“==” means that they are equal in value.
//( == )
//Each JavaScript value is of a specific “type” (Numbers, strings, Booleans, functions, and objects). So if you try to compare a string with a number, the browser will try to convert the string into a number before doing the comparison.
//So the following will return true.
55 == “55″ //true
0 == false //true
1 == true //true
//(===)
//The === operator will not do the conversion, if two values are not the same type it will return false. In other words, this returns true only if the operands are strictly equal in value or if they are identical objects.
55 === “55″ //false
0 === false //false
1 === true //false
var a = [1, 2, 3];
var b = [1, 2, 3];
var c = a;
var is_ab_eql = (a === b); // false (Here a and b are the same type,and also have the same value)
var is_ac_eql = (a === c); // true.
//Value types (numbers):
//a === b returns true if a and b have the same value and are of the same type.
//Reference types:
//a === b returns true if a and b reference the exact same object.
//Strings:
//a === b returns true if a and b are both strings and contain the exact same characters.
var a = “ab” + “c”;
var b = “abc”;
a === b //true
a == b //true
//in thiss case the above condition will fail
var a = new String(“abc”);
var b = “abc”;
a === b //false
a == b// true
//… since a and b are not a same type.
typeof “abc”; // ‘string’
typeof new String(“abc”)); // ‘object

的解释是_ab_eql
并没有真正解释任何东西。它们属于相同的类型,具有相同的值,但返回
false
。为什么?“对is_ab_eql的解释并没有真正解释任何东西。”解释:==表示值相等,==表示身份。同样地,在上面的示例中,a和c是相等的(引用存储器中的相同对象),a和b不是严格相等的(==),因为即使它们碰巧具有相同的值,它们引用不同的存储器部分。希望我能澄清上述问题。