I want to create a loop for part of my JavaScript code, I tried several methods, but they only return i=0 , my js code is
function format ( a ) {
var i;
for (i = 0; i <a.hr.length; i++) {
return '<table cellpadding="5" cellspacing="0" border="0" class="table">'+
'<thead>'+
'<tr>'+
'<th data-sortable="true">Full name:</th>'+
'<th>Extension number:</th>'+
'<th>Extra info:</th>'+
'<th>Extra info:</th>'+
'</tr>'+
'</thead>'+
'<tbody>'+
'<tr>'+
'<td>'+a.hr[i].position+'</td>'+
'<td>'+a.hr[i].salary+'</td>'+
'<td>'+a.hr[i].start_date+'</td>'+
'<td>'+a.hr[i].position+'</td>'+
'</tr>'+
'</tbody>'+
'</table>';
}
}
also I try:
function format ( a ) {
var i;
for (i = 0; i <a.hr.length; i++) {
return '<table cellpadding="5" cellspacing="0" border="0" class="table">'+
'<thead>'+
'<tr>'+
'<th data-sortable="true">Full name:</th>'+
'<th>Extension number:</th>'+
'<th>Extra info:</th>'+
'<th>Extra info:</th>'+
'</tr>'+
'</thead>'+
'<tbody>'+
for (i = 0; i <a.hre.length; i++) {
'<tr>'+
'<td>'+a.hr[i].position+'</td>'+
'<td>'+a.hr[i].salary+'</td>'+
'<td>'+a.hr[i].start_date+'</td>'+
'<td>'+a.hr[i].position+'</td>'+
'</tr>'+
}
'</tbody>'+
'</table>';
}
both methods return just i=0 , even I use for (i = 0; i <4 ; i++) { but still I get i=0. Would you please give me some tips in order to solve this problem?