What is the most elegant way to determine if all attributes in a javascript object are either null or the empty string? It should work for an arbitrary number of attributes
Based on tymeJv's answer =)
function checkProperties(obj) { var state = true; for (var key in obj) { if ( !( obj[key] === null || obj[key] === "" ) ) { state = false; break; } } return state; } var obj = { x: null, y: "", z: 1 } checkProperties(obj) //returns false
Hope it helps =)