function isEmpty(obj) {
for(var key in obj) {
return false;
}
return true;
}
What is wrong with this way of checking if an object is empty? I'm fairly new to JS and I'm going through SO to check what is the best and fastest way of checking if an object is empty and came across is this How do I test for an empty JavaScript object? among others.
All questions have similar answers checking Object.prototype.hasOwnProperty
which seems unnecessarily complicated. Is there a use-case where the code I've provided won't work and I should use the answers provided in the linked questions?