0
In a return of a method I have a resulting dictionary, sometimes it may come empty, hence I’m having trouble identifying when it is empty or not.
for(var i = 1; i <= this.last; i++)
{
this.select(i, (item) =>
{
console.debug(JSON.stringify(item));
if(item != null)
all.push(item);
});
}
The debug output is as follows:
database.ts:104 {"id":"1","descricao":"Alimentação"}
database.ts:104 {"id":"2","descricao":"Transporte"}
database.ts:104 {"id":"3","descricao":"Saúde"}
database.ts:104 {"id":"4","descricao":"Educação"}
database.ts:104 {}
database.ts:104 {}
database.ts:104 {"id":"7","descricao":"Mais uma conta"}
I want to run the all.push(item)
only when item is not vazio
, tried to use the .length
but it doesn’t work, I put console.log(item.length)
and in all cases returns undefined
. How can I check if it’s empty?
Set empty. No further information not sure if you can answer this.
– Maniero
Empty: Without any information inside, ie
{}
, I’ve already solved by manipulating the methodselect
to return false if you are unsuccessful in taking the data fromlocalStorage
. But I did not post the answer because it is not equivalent to the question. It would be to do the equivalent ofif(!empty($array))
in php andif(array.size() > 0)
in Java. But I didn’t find any option to check this in Typescript– Leonardo