Check if dictionary is null or empty?

0

In a return of a method I have a resulting dictionary, sometimes it may come empty, hence I have 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 output of the debug 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 execute all.push(item) only when item is not vazio , I tried to use .length but it does not work, I put console.log(item.length) and in all cases it returns undefined . How can I check if it is empty?

    
asked by anonymous 14.09.2016 / 19:48

1 answer

1

If you have not defined additional properties for your objects, you can use

...
if( Object.keys( item  ).length > 0 )
    all.push(item);
...

link

    
21.09.2016 / 14:07