Parsing And Displaying CSV Files In jQuery - csv.js

Parsing And Displaying CSV Files In jQuery - csv.js

csv.js is a jQuery based CSV parser that parses your CSV files and converts the CSV strings into JavaScript arrays and objects for further use. Ideal for dynamically generating data tables and data charts/graphs from CSV files. Supports both browser and node.js.

1. Insert the main JavaScript file csv.js after jQuery JavaScript library.

<script src="" 
<script src="src/jquery.csv.js"></script>

2. The JavaScript to parse a single line of CSV data into an array of values.


3. The JavaScript to parse CSV data into a JavaScript 2D (two-dimensional) array.


4. The JavaScript to parse CSV data into an array of objects.


5. Possible plugin options.

$.csv.functionName(csv, {
  // separator
  // delimiter
  // shows headers

6. Event handlers.

$.csv.functionName(csv, {
  onPreParse: function(){},
  onParseEntry: function(){},
  onParseValue: function(){},
  onPostParse: function(){},

7. Use the plugin in node.js.

var fs = require('fs');
var $ = jQuery = require('jQuery');
var sample = 'sample.csv';
fs.readFile(sample, 'UTF-8', function(err, csv) {
  $.csv.toArrays(csv, {}, function(err, data) {
    for(var i=0, len=data.length; i<len; i++) {

This awesome jQuery plugin is developed by JeremyMorgan. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 21.01.2018
  • Source