Skip to content
Advertisement

Sort arrays in alphabetical order and numeric order

JavaScript

So I have made the code above which fetches data from a .csv file and prints it out. I want to be able to print out the data in alphabetical and numerical order but I am not sure how to go about swapping them around. This is just a sample of data, the real list is about 100 lines long and I want to make sure all of them are sorted correctly in order. enter image description here

Advertisement

Answer

Assuming that ‘Class1.csv’ has no header and no special column for row names, and consists of rows separated by newline with values separated by comma, and has no empty values, and everything else, as I hope it is. Try this:

JavaScript

Next… to sort alphabetically:

JavaScript

Next… to sort numerically:

JavaScript
Advertisement