Home  >  Article  >  Web Front-end  >  What is the difference between substr and substring in javascript

What is the difference between substr and substring in javascript

王林
王林Original
2020-11-17 13:58:367655browse

The difference between substr and substring in javascript is: substr extracts a string of specified length starting from the starting index number; substring extracts the characters between two specified index numbers in the string.

What is the difference between substr and substring in javascript

Difference introduction:

(Video learning sharing: javascript video tutorial)

substr( start,length) is to extract a string of specified length starting from the starting index number;

substring(start,stop) is to extract the characters between two specified index numbers in the string; (same as in Java ), mathematically equivalent to extracting characters between [start,stop).

Example:

var letters = "abcdefg";
console.log(letters.substr(1,3))//结果为bcd
console.log(letters.substring(1,3));//结果为bc

Related recommendations:js tutorial

The above is the detailed content of What is the difference between substr and substring in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn