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

3 comments:

  1. Know About Online Passport Application Process Step by Step Process to apply Passport Online Application Form? Appointment Scheduling, click here to know more.
    online passport application form

    ReplyDelete
  2. Stay connected with your friends and family with Idea's Mobile internet. Get best plans and experience superfast Internet across India.
    Idea 3G Prepaid Tariff Plans

    ReplyDelete

My Blog List