javascript-csv-array-example
javascript-csv-array-example copied to clipboard
get data from outside
Hello, I thank you for Your code. I have a Question.
` myForm.addEventListener("submit", function (e) { e.preventDefault(); const input = csvFile.files[0]; const reader = new FileReader();
reader.onload = function (e) {
const text = e.target.result;
const data = csvToArray(text);
document.write(JSON.stringify(data));
};
reader.readAsText(input);
});
`
how can I get data from outside for use it in anover functions as Parameter?
best regards Wilhelm
Hi,
Do you mean you want to pass the array to another function as a parameter?
The csv data is saved under the variable data on line 47, so you just need to pass it into another function as you need.
In the example, I choose to write the output to the body at line 48, but you can pass it to another function there as well.
For example:
const data = csvToArray(text)
myFunction(data)
};
function myFunction(data){
// do something with data here...
}
Hi, thank You!