nathansebhastian / javascript-csv-array-example Goto Github PK
View Code? Open in Web Editor NEWJavaScript tutorial on how to convert CSV data to array
JavaScript tutorial on how to convert CSV data to array
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
Hello - I appreciate your work on this. Do you know how I might be able parse a file that's sitting in a directory on a server? Your code allows the user to add a file but I would need to parse from a file that's not uploaded manually. Thank you
My source CSV has values that contain commas. Every value has double quotes around it. How would I change this code to skip the commas that are inside of double quotes?
Code example:
ID,Full Name,Address
"85DD-019F","Alice","123 Park Ave, Topeka, KS, 66618"
I've tried setting the delimiter to '/,(?=(?:(?:[^"]*"){2})*[^"]*$)/'
(from this link) but then the array is the entirety of the row, then a bunch of undefined to fill out the rest of the values.
Hi Nathan,
Thanks for your excellent code. I am using it to read a CSV into my app from google sheets.
My issue is some of my fields have double quotes put around them by google sheets because the actual field contains commas.
e.g.
field1, "field 2, more field2, even more field2", field3
This seems to break the code somewhere in here I guess:
const values = row.split(delimiter);
const el = headers.reduce(function (object, header, index) {
object[header] = values[index];
Any ideas which bit is breaking? I guess it must be the 'split' function??
I'm a very average javascript coder :)
Thanks much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.