JavaScript比较两个对象的值是否相等
JavaScript比较两个对象的值是否相等
function isObjectValueEqual(a, b) { var aProps = Object.getOwnPropertyNames(a); var bProps = Object.getOwnPropertyNames(b); if (aProps.length != bProps.length) { return false; } for (var i = 0; i < aProps.length; i++) { var propName = aProps[i]; if (a[propName] !== b[propName]) { return false; } } return true; }
调用示例:
var isEqual=isObjectValueEqual({ "time": 1542244041000, "lon": 34.264245, "level": 1, "status": "", "color": "#58eb00", "value": 100.000000, "lat": 108.770303 }, { "time": 1542244041000, "lon": 34.264245, "level": 1, "status": "", "color": "#58eb00", "value": 100.000000 }); alert(isEqual);
如果这篇文章对您有帮助,您可以打赏我
技术交流QQ群:15129679