I have read the previous documents these days. When I see substring (), slice (), and substr (), I am not clear about the differences between them. After reading the materials and verifying them in person, I will make the following summary:
First, define a variable to facilitate the following test: var STR = 'q1207526854 'Str. substring (form, to): truncates a string with the subscript form to the subscript to (excluding the characters corresponding to) Alert (Str. substring (2075) // when form> to, substring takes a smaller parameter as the first parameter alert (Str. substring (6, 2) // 2075 and when one of the parameter values is negative, substring directly converts the negative number to 0. Alert (Str. substring (6,-2) // q12075 reverse Str. slice (Star, end): extracts from a string whose subscript is star to whose subscript is end (excluding the character corresponding to end) Alert (Str. slice (2075) // when star> end, slice returns an empty string alert (Str. slice (6, 2) // null when one of the parameter values is negative, slice will add the result of this parameter and the string length as the parameter alert (Str. slice (6,-2) // 268 and slice can operate on arrays. ---------------------------------------------------- Str. substr (Star, length): starting from a string whose subscript is star, truncates a substring of length, alert (Str. substr (207526) // when star is a negative number, substr adds the result of this parameter to the string length as the parameter alert (Str. substr (-6, 2) // 75 returns an empty string when the end value is negative. Alert (Str. substr (6,-2) // null