从概念上讲哪个应该更快?
String.charAt(0)
或 /^.{1}/
(正则表达式)
最佳答案
String.charAt(0)
,必须处理和应用正则表达式。
速度测试资源:
Paul S.
for the comparison test, http://jsperf.com/charat-vs-regex-vs-prop
joseph-the-dreamer
for adding more to the test, http://jsperf.com/charat-vs-regex-vs-prop/3
关于javascript - 性能 - String.charAt(0) 与/^.{1}/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15913406/