JSFiddle - React, Tailwind, and code Playground
by michapixel
HTML
<h4>Result: </h4>
<p id="res"></p>
JavaScript
Object.identical = function (a, b, sortArrays, loose) {
function sort(object) {
if (sortArrays === true && Array.isArray(object)) {
return object.sort();
}
else if (typeof object !== "object" || object === null) {
return object;
}
return Object.keys(object).sort().map(function(key) {
if(loose){
return {
key: key
};
}else{
return {
key: key,
value: sort(object[key])
};
}
});
}
return JSON.stringify(sort(a)) === JSON.stringify(sort(b));
};
var a = {
foo:'bar',
test:'null'
}
var b = {
foo:'bar',
test:'undefined'
}
var res = Object.identical(a, b, true);
$('#res').append(res === true ? 'true' : 'false');