本文介绍了localeCompare() 与 .Sort 用于按字母顺序排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按字母顺序对一组对象进行排序,但不确定哪种方式更有效.我目前使用 .sort() 方法并且它工作正常,但使用 localeCompare() 会是更好的选择吗?

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?

推荐答案

localeCompare 函数在许多浏览器上运行缓慢.如果可能,请避免它.其他语言环境功能也很糟糕,尤其是字符串的数字.

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.

这篇关于localeCompare() 与 .Sort 用于按字母顺序排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 09:58