I have this function which creates a table based on the values of an object.
function buildTable (){
//build header
var header = "<tr><th>USERS</th>"
for(var i=0; i<groups.length; i++){
header += "<th>"+groups[i]+"</th>";
}
header += "</tr>";
$("#taxonomy thead").append($(header));
//build table body
for(var user in userGroupTable){
var i = 0; i++;
var row ="<tr><td>" + usersName[i] + "</td>";
for(var i=0; i<groups.length; i++){
var groupName = groups[i];
var $td = "<td>"+userGroupTable[user][groupName]+"</td>";
row +=$td;
}
row += "</tr>";
//append the data to the table
$("#taxonomy tbody").append($(row));
}
}
I'm trying to iterate between the values in the usersName array but the way it's set up the var i get's reset to 0 on every loop so the same name keeps showing up. I'm not familiar with the for( var x in array), if there some sort of counter within this I can use to iterate through my array? Or should I just set a global variable?
Sorry if the title is poor.