localeCompare() vs .Sort for alphabetically sorting [duplicate]

霸气de小男生 提交于 2021-01-29 13:52:03

问题


Im sorting an array of objects alphabetically but not sure which way is more efficient. Im currently using the .sort() method and its working fine but would using the localeCompare() be a better alternative?


回答1:


The localeCompare function is absurdly slow on many browser. Avoid it if possible. The other locale functions are really bad too, particularly the number to string ones.



来源:https://stackoverflow.com/questions/55695675/localecompare-vs-sort-for-alphabetically-sorting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!