I have some fields where I pass some filters for a query in the database. I would like to check if the object is empty, so the query would not be performed.
I tried this way:
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}
I pass the object this way:
$scope.filtrarContratos = function(contrato) {
if(isEmpty(contrato)){
console.log("Inválido");
}
}
But the result is always false
.
This is the result I have in the console when I make an object console:
Object { contrato: "" }
I've tried an if to check if it was equal to ""
but it did not work either.