Troubles with global array

I’m trying to read the values of selected checkboxes. The checkboxes are filled with a valuelist and the checkboxes have a global variable as a dataprovider.

But, when reading the global variable array values and length I don’t quite get the result.
First of all, looping through the array gives two additional ‘\n’ after each value. Then, probably related, I get strange lengths for the array. When there is 1 value, i get the length ‘’, when there are 2 values I get the length ‘3.0’ and with 3 values I get ‘5.0’ and with 4, ‘7.0’, and so on…
Splitting the array with ‘\n’ gives good results, but only when there are at least 2 values in the array. The split function wouldnt obviously work when the length of the array says when having 1 value.
I don’t quite get the way why I get these results. I have this feeling that I don’t understand the way Servoy puts values in a global array, and/or javascript works with arrays. :( Why does it behave like this, is it normal?

My example code:

//Create checkboxes with global variable as dataprovider
var newVarTypesFld = newVariationsForm.newField('vartypes',SM_DISPLAYTYPE.CHECKS,180,100,160,200);
newVarTypesFld.dataProviderID = 'globals.createNewVarTypes';
newVarTypesFld.valuelist = solutionModel.getValueList('main_vartypes');

//Create new form method and attach to button
var newAddScript = "function newBtn() {";
newAddScript += "	var varTypes = globals.createNewVarTypes;";
newAddScript += "	for ( var i = 0; i < varTypes.length; i++ )";
newAddScript += "	   {";
newAddScript += "	       application.output(varTypes[i]);";
newAddScript += "	   }";
newAddScript += "	};";
var newAddMethod = newVariationsForm.newFormMethod(newAddScript);
var newAddBtn = newProductForm.newButton('Add Variations',180,380,120,20,newAddMethod);

// There are five checkboxes, all returning a number (1,2,3,4 or 5)
// Only when there are at least two checkboxes selected, the application outputs correct values
// When there is just one checkbox selected it returns "" (null)

Ok, found the problem. The valuelist that I use to populate the checkboxes didn’t had ‘allow empty value’ checked. That creates a problem when you just select one checkbox… argh :?