Sorting an array in JavaScript is handy with sort array method.
1 | const names = ['Sojiro', 'åshKeys', 'Sakaßato', 'Ashok M A', 'Zin', 'Kenshin', 'Himura']; |
The above gives the following sorted array in table format as we used console.table.
1 | ┌─────────┬─────────────┐ |
Notice that we used localeCompare as our sorting method. It is really useful for comparing strings from different locales. \O/
Tip: By default it takes it by the base of the letters irrespective of their locales as you can see in our example as well. ^_^