Differences between substring and substr in JS
Substring: This method can have either a parameter or two parameters. (1) One parameter: Example: var str = "Olive"; str. substring (3); Result: "ve" Description: When a substring has only one parameter, the parameter indicates the number of digits of the string to be intercepted and taken directly to the end of the string. (2) Two parameters: var str = "Olive"; 1) Str. substring (3, 4); 2) Str. substring (3, 2); Result: 1) "v" 2) 0 Note: When substring has two parameters, the first parameter indicates the number of the string to be truncated, the second parameter indicates the number of characters intercepted to the string. This is a different part of the character Truncation in C #, which leads to different results. Substr: This method can also have one or two parameters. (1) One parameter: Description: When substr is a parameter, the function is the same as when substring is a parameter. (2) Two parameters: var str = "Olive"; 1) Str. substr (3, 2); 2) Str. substr (3, 4); Result: 1) "ve" 2) "ve" NOTE: When substr has two parameters, the first parameter indicates the number of the string to be truncated, the second parameter indicates the number of characters intercepted. This is the same as the character Truncation in C #. Therefore, in future use, substr is recommended if you want to avoid the interception problem.