It would be great to have a .csv file reader that can take a 'key' as an input to the reader to create an associative array.
I am reading a .csv file that looks something like this (simplified):
State,ID,Population
Alabama,AL,1234
California,CA,5678
Hawaii,HI,90123
North Dakota,ND,45678
etc...
And I would like to use a .csv file reader to allow me to do something like this:
csv_to_associatve_array("file.csv", function(foo,'ID') {
// Where ID is foo's "key" using the ID column of the csv file
// Then access foo as an associative array something like this:
console.log(foo['ND'].State)
});
This should log 'North Dakota' to the console.
I've searched quite a bit and can't seem to find anything. Maybe I'm using the wrong keywords.
In any case, if you have a neat way to access csv data using a key, that would be spiffy. Else, if no alternative, do you know a way to create an associative array from a 'normal' js array that a noob can understand and access as array[ID].State?