text 阵列到CSV

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 阵列到CSV相关的知识,希望对你有一定的参考价值。

const arrayToCSV = (arr, delimiter = ',') =>
  arr.map(v => v.map(x => `"${x}"`).join(delimiter)).join('\n');
arrayToCSV([['a', 'b'], ['c', 'd']]); // '"a","b"\n"c","d"'
arrayToCSV([['a', 'b'], ['c', 'd']], ';'); // '"a";"b"\n"c";"d"'

Converts a 2D array to a comma-separated values (CSV) string.

Use Array.prototype.map() and Array.prototype.join(delimiter) to combine individual 1D arrays (rows) into strings. Use Array.prototype.join('\n') to combine all rows into a CSV string, separating each row with a newline. Omit the second argument, delimiter, to use a default delimiter of ,.

以上是关于text 阵列到CSV的主要内容,如果未能解决你的问题,请参考以下文章

SumoSelect 拒绝阵列

text numpy导入多阵列错误

text Javascript ES6阵列图

text 阵列

text 阵列和环钻孔机

text 阵列的方法,钻