Here is my code:
function getMelhorBloco(tamanho){
var blocoMelhor = {};
var testeEntrouBloco = true;
for(var i = 0; i < $scope.blocos.length; i++) {
if($scope.blocos[i].estado == "Livre") {
if(tamanho < $scope.blocos[i].tamanhoTotal) {
if(testeEntrouBloco) {
blocoMelhor.indice = $scope.blocos[i].idBloco;
blocoMelhor.tamanho = $scope.blocos[i].tamanhoTotal;
testeEntrouBloco = false;
} else {
if($scope.blocos[i].tamanhoTotal < blocoMelhor.tamanho) {
blocoMelhor.indice = $scope.blocos[i].idBloco;
blocoMelhor.tamanho = $scope.blocos[i].tamanhoTotal;
}
}
}
}
}
return blocoMelhor;
}
I was trying to check if my object "blocoMelhor" is null.
I tried
if(blocoMelhor == null){}
if(blocoMelhor == undefined){}
if(blocoMelhor ===null){}
and the method:
function isEmpty(obj){
for(var key in obj) {
if(obj.hasOwnProperty(key)){
return false;
}
return true;
}
}
I printed the value of "blocoMelhor" and the console gives me this: Object { }
Any suggestions?