I am getting an array of objects from my JSON response. Sometimes I am getting an array of length 1 with an empty object. How do I check that condition?
I tried with a few things-
myarray[0]=='empty' || myarray[0] == 'undefined'
or myarray.indexOf(0)== -1
But didn't solved the problem
You can use Object.keys() method to return all property names and check it's length:
Object.keys(myarray[0]).length === 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With