<script>
function generateCaseDetails(array, n)
{
row = '';
for( i = 0;i<array.length;i=i+n)
{
row+=
'<tr class = "'+(i%2==0 ? 'even' : '')+'">'+
for(j = 0; j < n ; ++j)
{
'<td><label>'+array[i+j].label+'</label><div>'+array[i+j].value+'</div></td>'+
}
'</tr>'
}
document.write(row);
}
a = 12.5;
b = 0.3;
c = 3.4;
d = 1.2;
caseDetails = [
{"label":"30 day exception ratio", "value":a},
{"label":"30 day exception turn ratio", "value":b},
{"label":"60 day exception ratio", "value":c},
{"label":"60 day exception turn ratio", "value":d}
]
generateCaseDetails(caseDetails, 2);
</script>
I'm trying to create rows and columns dynamically in a table using above method. It works only with the outer loop, i.e. keeping the columns fixed. I want the no. of columns to be dynamically decided based on the value passed in the parameter of the function. Somehow the inner loop is not working.
Am I doing a syntactical mistake ?
Thanks in advance!
EDIT
Expected output:
30 day exception ratio 30 day exception turn ratio
12.5 0.3
60 day exception ratio 60 day exception turn ratio
3.4 1.2
array[i+j]?