0

How can I find out why two Array instances are comparing unequal?

I have two Array instances that appear to be the same:

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", "" ]

The type and length are identical; each element is identical to the corresponding element in the other array:

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 ]

But somehow the arrays still compare unequal:

js> messageTexts == expectedMessageTexts
false
js> messageTexts === expectedMessageTexts
false

What can be different between those two, that would make them appear to be equal by all the earlier tests, but still compare unequal?

bignose
  • 30,281
  • 14
  • 77
  • 110
  • Other than their reference? `console.log(JSON.stringify(messageText) === JSON.stringify(expectedMessageText))` – briosheje Dec 13 '17 at 10:14
  • The difference is that both points to different memory location so we cant compare 2 object as it is. – Ashvin777 Dec 13 '17 at 10:23

0 Answers0