Loop Multidimensional Object

/** Example Multidimensional Object */
animal = {
	pig: 'yes',
	cat: 'no',
	other: {
		horse: 'yes',
		dog: 'no'
	}
}

/** Example Function */
objectLevel = 0;
function loopObject(object) {
	for (var key in object) {
		if  (object.hasOwnProperty(key)) {
				
			if (object[key] instanceof Object) {
				objectLevel++;
				loopObject(object[key]);
			}
			else {
				console.log('[objectLevel: ' + objectLevel + '] ' + key + ' -> ' + object[key]);
			}
		}
	}
	objectLevel = 0;
}

loopObject(animal);