Checking if an implied object is empty

An implied JavaScript object (e.g. var o = {};) will always be a truthy value. Since we have no index or length, there is no graceful way to check whether or not these variables have been populated. Here is a simple function to check for an implied object that has no data.

function isEmpty(obj) {
	for (var o in obj) {
		return false;
	return true;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>