Previously, a requirement was made to sort by the pinyin of the person's name, then NLS_SORT
sorted in the background through the parameters of Oracle, and then returned the results to the front end. Now want to see if the front-end pairs of strings in alphabetical order what should be done? To find the information, the method is recorded as follows.
[‘张三‘,‘李四‘,‘王五‘].sort((a,=> a.localeCompare(b, ‘zh-Hans-CN‘,{sensitivity: ‘accent‘}))
localeCompare
The syntax for the function is as follows:
referenceStr.localeCompare(compareString[, locales[, options]])
Parameters
comparestring the string to compare
locales is optional. A string or array of strings that represents one or more languages or regions that conform to the BCP 47 standard.
zh-Hans-CN (Chinese written using the Simplified script as used in mainland China)
Returns a number that indicates whether the reference string precedes, follows, or is the same as the comparison string in the sort.
- Returns 1 when the reference string is in front of the comparison string
- Returns 1 when a reference string is followed by a comparison string
- Simultaneous return 0
do not rely on a specific return value of 1 or 1. the values of positive and negative numbers that are returned between browsers (and between different browser versions) vary, because only the return value is required to be positive and negative in the Web specification, and no specific value is specified. Some browsers may return 2 or 2 or some other negative, positive value.
Reference
Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
https://segmentfault.com/q/1010000002546028
Javacript in alphabetical order