/* ------------------------ 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

  • काश - काश मुझे भी पीने की आदत होती,मैं कब का मुर्दा हो गया होता। छुटकारा मिलता आज के आतंकवाद से, किसी संतान भूमि में सो गया होता। मेरा एतबार कौन करेगा, मैंने मुर...
    2 months ago
  • काश - काश मुझे भी पीने की आदत होती,मैं कब का मुर्दा हो गया होता। छुटकारा मिलता आज के आतंकवाद से, किसी शमशान भूमि में सो गया होता। मेरा एतबार कौन करेगा, मैंने मुर...
    2 months ago
  • Kumaon University Nainital B.Ed entrance exam test result 2012 - कुमाऊँ विश्वविधालय, नैनीताल (उत्तराखण्ड)
    10 years ago