3 ms·
The same options [1] are built into `String.prototype.localeCompare` (which is just a handy shortcut for calling `Collator` [2]). So for example: ``` ['B 1', '
by bakkoting 4y ago
The same options [1] are built into `String.prototype.localeCompare` (which is just a handy shortcut for calling `Collator` [2]). So for example:
```
['B 1', 'A 20', 'A 3'].sort((a, b) => a.localeCompare(b, 'en', { numeric: true }))
// ['A 3', 'A 20', 'B 1']
```
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
[2] https://tc39.es/ecma402/#sup-String.prototype.localeCompare https://tc39.es/ecma402/#sup-String.prototype.localeCompare