Home > JavaScript > Checking if an implied object is empty

Checking if an implied object is empty

January 19th, 2009

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;
}
Share this Article:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • FriendFeed
  • LinkedIn
  • Netvibes
  • Reddit
  • Slashdot
  • StumbleUpon
  • Tumblr
  • Twitter

booshtukka JavaScript

  1. No comments yet.
  1. No trackbacks yet.