0

I have to loop in few data from server and export to csv file. While exporting I am getting the data in reverse order.

In the below code the index is starting from the first element and pushing the data. Is there a way wherein I can loop the data from the last element. Index should start from last element and come to first

Code:

      $.each(exportArray, function (index, value) 
    {                   
                        csvData.push(ProcurementRelatedUID[index] + "," +           ProcurementPurchaseId[index] + "," + ProcurementVendorName[index] + "," + ProcurementPlant[index]  + ","+ ProcurementPlannedDeliveryTime[index] + "," + ProcurementStorage[index] + "," + ProcurementInHouseProductionTime[index] + "," + ProcurementGRProcessing[index]);
                        });

        csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(output);

       $(this)
        .attr({
        'download': filename,
            'href': csvData,
            'target': '_blank'

    });
User37
  • 31
  • 2
  • 7
  • if it's just `index` you cans say `index = arraylength - (index+1)` or go for `reverse` – Mritunjay Aug 27 '15 at 13:56
  • u might want to use real javascript for low level functionality, and not the unnecessary jquery wrappers – Itay Moav -Malimovka Aug 27 '15 at 13:57
  • @Mritunjay You should make that an answer: `exportArray.reverse()`. – JMM Aug 27 '15 at 13:58
  • Yes Thanks all it worked with .reverse() – User37 Aug 27 '15 at 14:22
  • Is there any specific way where I can control the update of each data in a column of the csv file. I want few columns to be in text format and few in number format. For eg: . I want to update this row: totalStockInventory 250.000,10.000,0.000,0.000,2.500,30.000,700.000,10.000,250.000,0.000. However the exported csv file is not taking the decimal values. It is displaying as 250,10,0,0,2.5 etc – User37 Aug 28 '15 at 07:32

0 Answers0