如何读取csv文件的第一列

How to read the first column of csv file?

本文关键字:一列 csv 何读取 读取 文件      更新时间:2023-09-26

假设我有这样的CSV文件,看起来像:

age       1
gender    2
location  3
address   4

如何从第一列检索所有字符串?谢谢。

拨打电话:

$.ajax({
    url: '...',
    success: function(response) {
       readCSVFile(response);
    }
});

处理ajax调用的响应。

function readCSVFile(response) {
    var lines = response.split("'n");
    for (var i = 0; i < lines.length; i++) {
       var _firstColumn = lines[i].split(";")[0];     //First column (Split on the separator!)
       //Do your stuff
    }
};