I'm after parsing a .csv file and turning it into a jQuery array! Now I want to sort the list so that I can read its values in order of ID number (a value within the array). Here is my array:
$.ajax({
url: "path/to/file.csv",
success: function(data) {
var array1 = data.split("\n");
var array2 = new Array();
for (var i = 0; i < array1.length; i++) {
array2.push(array1[i].split(","));
...
}
array is in this format:
[0] = ID, TITLE, NUMBER
[1] = 1, Name1, 0 << ie: [1][0], [1][1], [1][2]
[2] = 2, Name2, 14
[3] = 3, Name3, 25
[4] = 4, Name4, 66
[5] = 5, Name5, 87
[6] =
In order to ignore the first (title) row and the last (empty) row, I use:
if($.isNumeric(array2[i][0])){
//do something
}
else {
//do nothing
}
The rest if the data gets used as required. However, sometimes the files are not in order. I would like to select the row that has ID '1' first, ID '2' next and so on...
[0] = ID, TITLE, NUMBER
[1] = 5, Name5, 87 << ie: [1][0], [1][1], [1][2]
[2] = 2, Name2, 14
[3] = 4, Name4, 66
[4] = 3, Name3, 25
[5] = 1, Name1, 0
[6] =
Is there a way I can sort the array list? Or would I need to read the data to see whats there each time? (i.e. iterate through the list to find out what row my next ID is on)