Javascript does not provide isEmpty() method to check object if it is null/empty. However, it does provide a enumerator so we can test object if it at least has one item.
1 2 3 4 5 6 | function isEmptyObject(obj) { for (var key in obj) { return false; } return true; } |
function isEmptyObject(obj) { for (var key in obj) { return false; } return true; }
This is a tricky implementation and it does not bring too much performance overhead because the look-break immediately after the first item is tested.
References
1. http://leonax.net/p/7058/check-if-object-is-null-in-javascript/
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading...
142 wordsloading...
Last Post: How to Call Win32 APIs in C++ code - Quick Tutorial
Next Post: How to Disable Content Output in RSS Feed for WordPress?