Fawaz Alazemi Fawaz Alazemi - 1 year ago 82
Javascript Question

How to extract information in a TSV file and save it in an array in JavaScript ?

I'm running into a problem. If I have only tsv's file name. How can i extract all its information and save it in an array, say X, where each row in the tsv file is represented by an array, say y, where X is an array of ys.

ALso how can i do this if i don't know the headers of columns names ?

Answer Source
// get file contents, store in var str
var x = str.split('\n');
for (var i=0; i<x.length; i++) {
    y = x[i].split('\t');
    x[i] = y;


For help on how to get the file contents, you'll need to specify where these files will be located (on the client machine, server, etc.).

If the files are located on the client machine, you might have a rough road ahead of you.

If the files are located on the server, you'll need to do an AJAX request to get the file contents.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download