title: How to get the values of each row of a .txt(CSV) file array
body: <p>I am trying to get the values of an array (example trips_list.trip_id should pour out all the trip_id(s) of the array trips_list.)</p>
  
  <pre><code>.trips.txt file :
  route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,shape_id,wheelchair_accessible,bikes_allowed
  TaSj-16APR,CT-16APR-Caltrain-Saturday-02,23a,DIRIDON STATION,23,0,cal_tam_sj,,
  TaSj-16APR,CT-16APR-Caltrain-Saturday-02,25a,DIRIDON STATION,25,0,cal_tam_sj,,
  TaSj-16APR,CT-16APR-Caltrain-Saturday-02,27a,DIRIDON STATION,27,0,cal_tam_sj,,.................
  </code></pre>
  
  <p>Here is what I have for now :</p>
  
  <pre><code>function get(url) {
    return new Promise(function(resolve, reject) {
      var req = new XMLHttpRequest();
      req.open('GET', url);
      req.onload = function() {
        if (req.status == 200) {
          resolve(req.response);
        }
        else {
          reject(Error(req.statusText));
        }
      };
      req.onerror = function() {
        reject(Error("Network Error"));
      };
      req.send();
    });
  }
      get('../data/trips.txt').then(function(response) {
    //console.log("Success!", response.split(/(\r\n|\n)/));
    var trips_list = response.split(/(\r\n|\n)/);
    if(Array.isArray(trips_list)) {
      console.log('true');
    } else {
      console.log('Not An Array')
    }
    var re = /,/;
    var headers = trips_list.shift().split(re);
    var route_id = headers.indexOf("route_id");
    var service_id = headers.indexOf("service_id");
    var trip_id = headers.indexOf("trip_id");
    var trip_headsign = headers.indexOf("trip_headsign");
    var mainArray = trips_list.map(function(val, key) {
      return val.split(re);
    }).filter(Boolean);
  
    var trip_id = headers.indexOf("trip_id");
    var tripid = trips_list.map(function(val, key) {
      return val.split(re)[trip_id];
    }).filter(Boolean);
  
     var service_id = headers.indexOf("service_id");
    var serviceid = trips_list.map(function(val, key) {
      return val.split(re)[service_id];
    }).filter(Boolean);
  
    var route_id = headers.indexOf("route_id");
    var routeid = trips_list.map(function(val, key) {
      return val.split(re)[route_id];
    }).filter(Boolean);
  
  
     var tripstr = '';
      var i;
      for (i = 0; i &lt; routeid.length; i++) {
         tripstr += '&lt;div class="tripper"&gt;&lt;b&gt;RID:&lt;/b&gt; &lt;em&gt;'+routeid[i]+'&lt;/em&gt; &lt;b&gt;SID:&lt;/b&gt; &lt;em&gt;'+serviceid[i]+'&lt;/em&gt; &lt;b&gt;TID:&lt;/b&gt; &lt;em&gt;'+tripid[i]+'&lt;/em&gt;&lt;/div&gt;';
      }
  
      tripResults.innerHTML = tripstr;
      //console.log(tripstr);
  }, function(error) {
    console.error("Failed!", error);
  });
  </code></pre>
  
  <p>Browser output:</p>
  
  <pre><code>RID: SID: CT-16APR-Caltrain-Saturday-02 TID: 23a
  RID: TaSj-16APR SID: CT-16APR-Caltrain-Saturday-02 TID: 25a
  RID: SID: CT-16APR-Caltrain-Saturday-02 TID: 27a
  RID: TaSj-16APR SID: CT-16APR-Caltrain-Saturday-02 TID: 01a
  RID: SID: CT-16APR-Caltrain-Saturday-02 TID: 29a
  RID: TaSj-16APR SID: CT-16APR-Caltrain-Saturday-02 TID: 31a
  RID: SID: CT-16APR-Caltrain-Saturday-02 TID: 33a.................
  RID: Lo-16APR SID: undefined TID: undefined
  RID: SID: undefined TID: undefined
  RID: Lo-16APR SID: undefined TID: undefined
  RID: SID: undefined TID: undefined
  RID: Lo-16APR SID: undefined TID: undefined
  RID: SID: undefined TID: undefined
  RID: Lo-16APR SID: undefined TID: undefined
  </code></pre>
  
  <p>My output is skipping values and sometimes printing out undefine. Any better way to get the values(<strong>route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,shape_id,wheelchair_accessible,bikes_allowed</strong>) of the text file for each row?</p>