0

$.each(val, function(ind, va) {
  console.log(ind)
  console.log(va)
  if (value.deductiontype == "1") {
    var row = $('<div class="row" style="margin-top:6px;"><div class="col-md-12"><div class="col-md-2"><label class=" col-form-label">' + ind + '</label></div><div class="col-md-10"><input class="form-control payments" type="text" id="" placeholder="' + ind + '" value="' + va + '"/><div></div></div>');

    $("#deduction_end_date").closest(".row").after(row);
  } else if (value.deductiontype == "2") {
    var row = $('<div class="row" style="margin-top:6px;"><div class="col-md-12"><div class="form-group"><div class="col-md-2"><label class=" col-form-label">' + ind + '</label></div><div class="col-md-10"><input class="form-control payments" type="text" id="" placeholder="' + ind + '" value="' + va + '"/></div></div></div></div>');
    $("#deduction_end_date").closest(".row").after(row);
  } else {

  }

});

I have above code. what it does is it appends data on a table by iterating over the passed data. It is working ok except that the data in the table are from last to first.

I want to append the data from first to last

How can I use .after() in a way that it will append from first to last

Martin
  • 365
  • 4
  • 7
  • 22

1 Answers1

1

I want to append the data from first to last, You can simply use .reverse() the array.

The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.

$.each(val.reverse(), function(ind, va) {

});
Satpal
  • 132,252
  • 13
  • 159
  • 168