0

I have an excel file with this data

enter image description here the file was saved as a CSV file. Then I used this function to read an display the file content.

    var fileInput = document.getElementById("csv");

      readFile = function () {

              console.log("file uploaded");
              var reader = new FileReader();
              reader.onload = function () {
            reader.readAsBinaryString(fileInput.files[0]);
            };
            }
            if (fileInput){
                fileInput.addEventListener('change', readFile);
            }

the function output the image below. What i want to do is to append the function output to an array in this format ["75799757","9744710",...] so that I can use the function below to iterate through each ID to perform a function.

   myStringArray.forEach( function(s) { 
                       // ... do something with s ...
                  } );

I know one can append output to an array using the .push() function but How can I append the output to an array so that it will be in this format ["75799757","9744710",...] with quotation mark and commas?

enter image description here

e.iluf
  • 1,389
  • 5
  • 27
  • 69
  • 1
    i think you can just `split` that string by space and remove the item at 0 position since it will be ID. If you inspect this page and type `"id 223432 32432423 4234324".split(" ")` in console, you will see what you want – Huangism Jun 29 '17 at 16:47
  • It would be helpful if you showed your data as text rather than images... – Heretic Monkey Jun 29 '17 at 16:48
  • If you want to make an array, you'll want to create an array instead of a string that looks like an array. Follow answers from questions like this [one](https://stackoverflow.com/questions/7431268/how-to-read-data-from-csv-file-using-javascript/12289296#12289296) to get an idea about how to get data from a CSV. From there just push each value into a array that you have created. – Nick Wyman Jun 29 '17 at 17:33
  • You might be interested with this library https://github.com/mholt/PapaParse – Fahmi Jun 29 '17 at 17:43

0 Answers0