subString(start,stop)
substr(start,length)
Both substr and substring are intercepted strings.
The two have the same point. If only one parameter is written, the function of both is the same: that is to intercept the string fragment after the current subscript of the string until the end of the string.
E.g:
`var a=”abcdefghiklmnopqrstuvwxyz”;
var b=a.substr(3);
var c=a.substring(3);
console.log(b);
console.log(c);
In this way, the output results are the same, which are all defghiklmnopqrstuvwxyz
intercepted from the position where the third subscript is 2 to the end. When writing the second parameter, the two will have completely different meanings; substr(a,b) The second parameter is the length of the intercepted string substring(a, b) The second parameter is the final subscript of the intercepted string. For example:
var a="abcdefghiklmnopqrstuvwxyz";
var b=a.substr(3,5); var c=a.substring(3,5); 打印输出的结果是: defgh de 注意最后5下标是不会取到的意思是只能截取a字符串的3,4下标 截取的时候是不会截取到最后一个[3,5)