I have object whose (JSON.stringify) looks like:
"{"test":[{"header":{"test":1}}]}"
and another object which looks like:
"{"test":1}"
Now if I try this:
firstObj.test[0].header == secondObj
javascript says false. Why?
As others here point out, object comparison in JS is same-instance comparison, not value comparison. For your limited example, comparing instead the results of JSON.stringify() would seem to work, but if you cannot guarantee the order of properties (which JS does not), then that won't work either. See Object comparison in JavaScript for details. That link has a more intricate answer, but if you know the objects you're comparing then the best test of comparison is a specific one IMHO, e.g. test for the properties you care about. Objects can be anything in JS, therefore, thinking of objects as being "equal" does not make sense outside a specific context.
JSON.stringify({a:1,b:1}) !== JSON.stringify({b:1,a:1}) Comparing objects using JSON.stringify is a bad idea.
stringandint) to simulate the comparation and obtaintrueif needed, ask if you need more info to achieve it