© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Dev By RayRay
Tech Lead / Lead Developer in the 🇳🇱 https://byrayray.dev/
The simplest way to convert a CSV file into a JavaScript Array of Objects is, using the JavaScript split, map, forEach, trim methods, and spread operator. In this post, I love to show you how you can exactly do that by using a file upload form. In t...
Hey RayRay,
Thanks for this, it was super helpful with my project.
I had one small issue with \r being inserted into my column 2 keys and values which sounds like it was the same as Mohd.
Here was my solution:
const csvArray = csvToArr(e.target.result, ","); csvArray.value = JSON.stringify(csvArray, null, 2).replaceAll("\\r","");
Simply just use replaceAll to remove the '\r's.
There is probably a nicer way to do that, but this is good enough for me.
Thanks again.
Bryon
TooMuchTofu
I like to eat tofu
I'm happy that it was helpful to you!
Thanks for the suggestion, I'm gonna look into it. Did you use the data in the post? Or did you use your data? Maybe there is a difference in it.
Mohd Shakree Elmi Azmee
Hello,
I'm new to Javascript, after trying the above, I realize there is '\r' at the end of the last column (including the rows). How do I fix this?
Thank you.
Nevermind, I got it working.
I used .replace to remove the \r.
Thanks!
Mohd Shakree Elmi Azmee I'm happy you got it working 👍 This perfectly fits in the process of being a developer right 😅
Hey RayRay,
Thanks for this, it was super helpful with my project.
I had one small issue with \r being inserted into my column 2 keys and values which sounds like it was the same as Mohd.
Here was my solution:
const csvArray = csvToArr(e.target.result, ","); csvArray.value = JSON.stringify(csvArray, null, 2).replaceAll("\\r","");Simply just use replaceAll to remove the '\r's.
There is probably a nicer way to do that, but this is good enough for me.
Thanks again.
Bryon