Notes

JavaScript - substring vs substr

author: Paul Kim

categories: js

tags: js

String.prototype.substring() vs String.prototype.substr()

Note: substr() is considered a legacy function. use substring() instead.

The difference between substring() and substr() is in the 2nd parameter:

  • substring() - the index of the first character to exclude
  • substr() - the length of characters to extract.
substring(indexStart)
substring(indexStart, indexEnd)

substr(start)
substr(start, length)
Source

ChromeEdgeFirefoxOpera

© 2021 paulkode.com. All rights reserved.