javascript - CSV node.js, from file to array -


i've been trying ages no avail (some returning 'null'). i'm trying csv (which contain on 2.2 million elements):

rough,lukk,black,semnas,mickayrex

to read javascript array.

currently, have fixed array

var usernames = ['mickayrex', 'black']; 

and goal able put names text file array format above use rest of program.

here function book "javascript functional programming" parse csv array (i have modified avoid use underscore):

function parsecsv(str) {    var rows = str.split('\n');      return rows.reduce(function(table, row) {      var cols = row.split(',');        table.push(cols.map(function(c) {        return c.trim();      }));        return table;    }, []);  }    var frameworks = 'framework, language, age\n ' +                   'rails, ruby, 10\n' +                   'node.js, javascript, 5\n' +                   'phoenix, elixir, 1';    var array = parsecsv(frameworks);  console.log(array);    var consoleel = document.queryselector('#console');  consoleel.innerhtml = 'array content: '+array;
<div id="console"></div>


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -