如何找出两个Array
实例比较不等的原因?
我有两个看似相同的Array
个实例:
js> messageTexts
Array [ "Nostrum porro quo laborum", "Corrupti animi architecto dicta", "Lorem ipsum, dolor sit amet", "Nulla ipsa veniam eveniet veniam", "" ]
js> expectedMessageTexts
Array [ "Nostrum porro quo laborum", "Corrupti animi architecto dicta", "Lorem ipsum, dolor sit amet", "Nulla ipsa veniam eveniet veniam", "" ]
类型和长度相同;每个元素与另一个数组中的对应元素相同:
js> typeof(messageTexts) === typeof(expectedMessageTexts)
true
js> messageTexts.length === expectedMessageTexts.length
true
js> messageTexts.map(function (item, index) {return item === expectedMessageTexts[index];})
Array [ true, true, true, true, true ]
js> expectedMessageTexts.map(function (item, index) {return item === messageTexts[index];})
Array [ true, true, true, true, true ]
但不知何故,阵列仍然比较不平等:
js> messageTexts == expectedMessageTexts
false
js> messageTexts === expectedMessageTexts
false
这两者之间可能有什么不同,这会使它们在所有早期测试中看起来相同,但仍然比较不相等?