The usage of substr, substring, indexOf and LastIndexOf in JS
Substr
SUBSTR (Start,length), which starts from the start position, intercepts the length string
`var str="imgs/header_2.jpg"; console.log(str.substr(5,6));` 输出值为:header
Substring
SUBSTRING (start,end) represents a string from start to end, including start but not end
`var str=‘imgs/header_2.jpg;’ alert(str.substring(5,11));‘ 弹出值为:header
IndexOf
The IndexOf () method returns the position (left-to-right) of the first occurrence of a specified string value in a string. Returns 1 if there is no match, otherwise returns the subscript value when the string first appears.
`var str=‘imgs/header_2.jpg‘; alert(str.indexOf(‘w‘); alert(str.indexOf(‘i‘); alert(str.indexOf(‘e‘);`弹出值依次为:-1,0,6
LastIndexOf
The LastIndexOf () method returns the first character index value of a character or string that appears from right to left (as opposed to indexof);
`var str="imgs/header_2.jpg"; alert(str.lastIndexOf(‘/‘)); alert(str.lastIndexOf(‘g‘);` 弹出值依次是:4,16
# JS in the use of substr, substring, indexOf, LastIndexOf