javascript - Loop through array and display result in table style -


i have following array:

var arr = ['1---william---developer', '2---winston---staff', '3---thomson---admin']; 

i want split , allocate table.

example:

<tr>     <td>1</td>     <td>william</td>     <td>developer</td> </tr> <tr>     <td>2</td>     <td>winston</td>     <td>staff</td> </tr> <tr>     <td>3</td>     <td>thomson</td>     <td>admin</td> </tr> 

here code tried

var = "";  var b = "";  (i = 0; < worker_row_array.length; i++) {       var row_item = worker_array[i];      var row = "<tr>";      var worker_item_array = row_item.split("---");      (var s = 0; s < worker_item_array.length; s++) {          column_item = worker_array_list[s];          b += "<td>"+column_item+"</td>";      }     += b.concat("</tr>"); } 

you need name arrays same define them

i reused original code:

var  worker_row_array = ['1---william---developer', '2---winston---staff', '3---thomson---admin'];    var = "";  (i = 0; < worker_row_array.length; i++) {        var row_item = worker_row_array[i];       var row = "<tr>";       var worker_item_array = row_item.split("---");       (var s = 0; s < worker_item_array.length; s++) {           column_item = worker_item_array[s];           row += "<td>"+column_item+"</td>";       }       += row+"</tr>";  }  = "<table>"+a+"</table>";  console.log(a);  document.getelementbyid("workers").innerhtml=a;
<div id="workers"></div>


Comments