📜  CSV 到 2D 数组 javaescript - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:17.138000             🧑  作者: Mango

代码示例1
function csvToArray(csv, delimiter = ",", omitFirstRow = false) {
  console.log(csv.indexOf('\n'));
  return csv.slice(omitFirstRow ? csv.indexOf('\n')+1 : 0)
            .split("\n")
            .map((element) => element.split(delimiter));
}

let csv1 = "a,b\nc,d";
let csv2 = "a;b\nc;d";
let csv3 = "head1,head2\na,b\nc,d";

let result1 = csvToArray(csv1);
let result2 = csvToArray(csv2);
let result3 = csvToArray(csv3);

console.log(result1);
console.log(result2);
console.log(result3);