Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript sorts alphabetically

Shulou Source: shulou.com Published: 2022-06-01 04:26:50 09月22日 Update

This article will explain in detail how JavaScript is sorted alphabetically. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.

are sorted alphabetically

In cross-international projects, some special languages may have problems sorting by dictionary, as shown below😨

//Wrong approach ["a", "z", "ä"].sort((a, b) => a - b);// ['a', 'z','ä']//Correct approach ["a", "z", "ä"].sort((a, b) => a.localeCompare(b));// [ 'a', 'ä', ' z']

localeCompare() : Compare two strings in a locally-specific order.

About "JavaScript how to sort alphabetically" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Order sort letters articles practices more good practical special two content dictionaries characters strings articles knowledge language errors problems items Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Microsoft Redmi Linux