Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7627267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:26:11+00:00 2026-05-31T05:26:11+00:00

I was wondering about Javascript performance about using string.replace() or string.substr(). Let me explain

  • 0

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!)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:26:12+00:00Added an answer on May 31, 2026 at 5:26 am

    For performance tests in JavaScript use jsPerf.com

    I created a testcase for your question here, which shows, that substr is a lot faster (at least in firefox).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering about this... I have several separate javascript files, that all contain code
Just wondering about the performance impact of copying very large php variables. For example
Just wondering about how to avoid Magic Strings in Querystrings? I have a lot
I have been wondering about the performance of regular expression implementations lately, and have
I've been wondering about JavaScript's prototypal nature, and the benefits of it, and have
I just heard about JavaScript objects and was wondering what they are (because I
I've been wondering about the performance improvements touted in Java SE 6 - is
I'm just wondering about large projects - say an airlines reservation system, how many
I have a question about Javascript widgets. The widget I am working on simply
I am wondering about javascript prototype. I know that prototyping enables the user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.