128
rated 0 times
[
131]
[
3]
/ answers: 1 / hits: 15341
/ 13 Years ago, tue, march 6, 2012, 12:00:00
I was wondering about Javascript performance about using string.replace() or string.substr(). Let me explain what I'm doing.
I've a string like
str = a.aa.a.aa.
I just have to pop last element in str where I always know what type of character it is (e.g, it's a dot here).
It's so simple, I can follow a lot of ways, like
str = str.substr(0, str.length-1) // same as using slice()
or
str = str.replace(/.$/, '')
Which methods would you use? Why? Is there some lack in performance using this or that method? Length of the string is negligible.
(this is my first post, so if I'm doing something wrong please, notify me!)
More From » regex