Quantcast
Channel: Zeroed & Noughted » JavaScript
Viewing all articles
Browse latest Browse all 10

Checking if an implied object is empty

$
0
0

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;
}

Viewing all articles
Browse latest Browse all 10

Trending Articles