Skip to content

Instantly share code, notes, and snippets.

@edinella
Created October 25, 2013 12:31
Show Gist options
  • Save edinella/7153960 to your computer and use it in GitHub Desktop.
Save edinella/7153960 to your computer and use it in GitHub Desktop.
JS to CSV
var dados = [
['Nome', 'Sobrenome', 'Profissão'],
['Paula', 'Tejando', 'Adivinha' ],
['Cuca', 'Beludo', 'Padeiro' ],
['Thomas', 'Turbano', 'Popeye' ]
];
var csv = dados.map(function(linha){
return linha.map(function(celula){
return '"'+(celula.replace(/\"/g, '\"').replace(/\r/g, '\\r'))+'"';
}).join(';');
}).join('\n');
console.log(csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment