I’m having an issue comparing objects encoded and decoded to and from JSON
//Test data
var test_obj = {
test:'value',
t:3,
x:[0,5,3]
};
var t = JSON.stringify(test_obj);
var t_prime = JSON.parse(t);
You’d think that test_obj === t_prime would return true,
or perhaps test_obj == t_prime would return true, but this is not the case.
Why is this, and how can I verify that I get the same object to and from a javascript object to JSON?
When you compare objects in JS, you are checking to see if they are the same object and not identical objects.
Converting to JSON turns an object into a string. Converting from JSON creates a new object based on the JSON data.
If you want to check if two objects are identical, then see How do you determine equality for two JavaScript objects?.