I hope this makes sense. If I have an object:
var a = {"minlength":true}
var a = {}
How can I tell if the object is empty (the second line of code)
I hope this makes sense. If I have an object:
var a = {"minlength":true}
var a = {}
How can I tell if the object is empty (the second line of code)
Object.keys(a).length === 0
should do the trick.
You should check for undefined as well:
if (a != undefined) {
// object is defined, you can do stuff now
}
Object.keys(a)
returns a list of keys, so Object.keys(a).length == 0
means it's empty.