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...

Markdown supported · ⌘↵ to post
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.
TooMuchTofu
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