/* ------------------------ My Meta Content Here SEO ------------------------ */

Pages

Main Menu

Monday, February 27, 2017

How to get odd/even value from array and display in table using Javascript

var dataArr = ["1","Maths","2","Science"];
Add a bare bones table to a div.
$("#subjectTable").append('
'
);
For each table row loop over the array in steps of 2 (i+=2). oddPositionVal is the first element in the step, evenPositionVal is the second element.
Build the row HTML and then append it to the table.

for (var i = 0, l = dataArr.length; i < l; i+=2) {
  var oddPositionVal = dataArr[i];
  var evenPositionVal = dataArr[i + 1];
  var rowhtml = ' ' + oddPositionVal + '' + evenPositionVal + ' ';
  $('#table').append(rowhtml);
}
http://stackoverflow.com/questions/25761856/how-to-get-odd-even-value-from-array-and-display-in-table-using-javascript 
Read More »

My Blog List