Home > Article > Web Front-end > What is the difference between substr and substring in javascript
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.
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!