Usage of substr, substring, indexOf, lastIndexOf, etc. in js
1.substr
substr(start, length) means starting from the start position, intercepting a string of length length.
var src="images/off_1.png";
alert(src.substr(7,3));
The pop-up value is: off
2.substring
substring(start,end) represents the string from start to end, including the character at the start position but excluding the character at the end position.
var src="images/off_1.png";
alert(src.substring(7,10));
The pop-up value is: off
3.indexOF
indexOf() method returns the position (from left to right) where a specified string value first appears in the string. If there is no match, -1 is returned, otherwise the subscript value of the string at which the first occurrence occurs is returned.
var src="images/off_1.png";
alert(src.indexOf('t'));
alert(src.indexOf('i'));
alert(src .indexOf('g'));
The pop-up values are: -1,0,3
4.lastIndexOf
lastIndexOf() method returns the first character index value of a certain character or string from right to left (opposite to indexOf)
var src="images/off_1.png";
alert(src.lastIndexOf('/'));
alert(src.lastIndexOf('g'));
The pop-up values are: 6, 15