This is my code and it gets options from a jsTree checkbox tree list:
var level1, r = [];
for (i = 0, j = data.selected.length; i < j; i++) {
    r[0] = data.instance.get_node(data.selected[i]).text.trim();
    r[1] = data.instance.get_node(data.selected[i]).parents.length;
    if(r[1] == 1) {
       level1 += r[0] + ", ";
       alert(level1);
    }
}
The alert of the above contains undefined along with the correct choices from the checkboxes.  Any idea why I am getting undefined in the output?
 
     
     
    