I have the following text file stops.txt
.
stop_id,stop_code,stop_name,stop_lat,stop_lon,zone_id,stop_url,location_type,parent_station,platform_code,wheelchair_boarding
70011,70011,San Francisco Caltrain,37.77639,-122.394992,1,http://www.caltrain.com/stations/sanfranciscostation.html,0,ctsf,NB,1
70012,70012,San Francisco Caltrain,37.776348,-122.394935,1,http://www.caltrain.com/stations/sanfranciscostation.html,0,ctsf,SB,1
70021,70021,22nd St Caltrain,37.757599,-122.39188,1,http://www.caltrain.com/stations/22ndstreetstation.html,0,ct22,NB,2
70022,70022,22nd St Caltrain,37.757583,-122.392404,1,http://www.caltrain.com/stations/22ndstreetstation.html,0,ct22,SB,2
Here is my javascript function to get the stop_names index to a datalist
:
get('../data/stops.txt').then(function(response) {
//console.log("Success!", response.split(/(\r\n|\n)/));
var stop_list = response.split(/(\r\n|\n)/);
var re = /,/;
var headers = stop_list.shift().split(re);
var index = headers.indexOf("stop_name");
//Removing [index] at return val.split(re)[index]; should return an array of arrays of each split value
var res = stop_list.map(function(val, key) {
return val.split(re)[index];
}).filter(Boolean);
var str = '';
var i;
for (i = 0; i < res.length; i++) {
str += '<option value="'+res[i]+'" />';
}
var s_list=document.getElementById("slist");
s_list.innerHTML = str;
}, function(error) {
console.error("Failed!", error);
});
This works just perfect. But since the first row is having the same stop name as row 2.
What I want is to get just one result set of stop_name if stop_name and plate_form is the same.