JSFiddle - React, Tailwind, and code Playground
by John Grivas
HTML
<input type="hidden" id="remoteJSON" name="remoteJSON" value='{"allowExternalMembers": "false", "whoCanJoin": "CAN_REQUEST_TO_JOIN"}' /><br />
<input type="hidden" id="localJSON" name="localJSON" value='{"whoCanJoin": "CAN_REQUEST_TO_JOIN", "allowExternalMembers": "false"}' /><br />
CSS
"{\"allowExternalMembers\": \"false\", \"whoCanJoin\": \"CAN_REQUEST_TO_JOIN\"}"
"{\"whoCanJoin\": \"CAN_REQUEST_TO_JOIN\", \"allowExternalMembers\": \"false\"}"
JavaScript
var k = $("#remoteJSON").val();
k= JSON.stringify(k); // '{"name":"binchen"}'
var l = $("#localJSON").val();
l= JSON.stringify(l);
document.write(k)
document.write(l)
alert(objectEquals(k,l));
function objectEquals(x, y) {
// if both are function
if (x instanceof Function) {
if (y instanceof Function) {
return x.toString() === y.toString();
}
return false;
}
if (x === null || x === undefined || y === null || y === undefined) { return x === y; }
if (x === y || x.valueOf() === y.valueOf()) { return true; }
// if one of them is date, they must had equal valueOf
if (x instanceof Date) { return false; }
if (y instanceof Date) { return false; }
// if they are not function or strictly equal, they both need to be Objects
if (!(x instanceof Object)) { return false; }
if (!(y instanceof Object)) { return false; }
var p = Object.keys(x);
return Object.keys(y).every(function (i) { return p.indexOf(i) !== -1; }) ?
p.every(function (i) { return objectEquals(x[i], y[i]); }) : false;
}