February 2019
Beginner to intermediate
284 pages
6h 20m
English
There is no native CSV parser in JavaScript, but if you have a very small and simple CSV file, you can parse it using JavaScript string manipulation tools or regular expressions, splitting by newlines (\n) to select each row, and then splitting by the delimiter to select each data cell within each row.
Larger data files are more complex, since the preceding code depends on a specific format and does not deal with commas inside quoted strings, missing data, and so on. In this case, you should use a CSV parser. Most examples in this book use the PapaParse CSV parser (papaparse.com) by Matt Holt, which is open source and free. The following code shows how to convert CSV into a JavaScript object using PapaParse:
const csvData = Papa.parse(csvText, ...
Read now
Unlock full access