JS implements alphabetical ordering of provinces and cities
A recent project has a requirement to sort the array of provinces and cities returned by the backend by the first letter (AZ). I referred to https://blog.csdn.net/kuangruike/article/details/54139694, which was written using JQuery Yes, I am using native js
1. The data returned by the backend
![Insert image description here](https://img-blog.csdnimg.cn/20210303105102642.png)
2. The last data obtained
![Insert image description here](https://img-blog.csdnimg.cn/20210303105246138.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3doMTM4MjE2NjIyNTk=,size_16,color_FFFFFF,t_70)
That is, there are ten places under the initial letter "A"
3 function
pySegSort(arr) {
if (!String.prototype.localeCompare) return null;
var letters = "*ABCDEFGHJKLMNOPQRSTWXYZ".split("");
var zh = "阿八嚓哒妸发旮哈讥咔垃痳拏噢妑七呥扨它穵夕丫帀".split("");
var segs = [];
var curr;
letters.forEach(function (item, i) {
curr = { lette