1.indexOf() method, finds the string position from front to back, is case sensitive, and counts from 0. Similarly, the lastIndexOf() method is from the back to the front, and the results of the two methods output the same search conditions are the same.
For example:
The code copy is as follows:
<script type="text/javascript">
var str="Hello World!"
document.write(str.indexOf("Hello"))//Output 0
document.write(str.indexOf("World"))//Output 6
document.write(str.indexOf("world"))//Output-1, because it was not found
</script>
2.length, accessed in the form of "XXX.length", because it is a method of string object
The code copy is as follows:
<script type="text/javascript">
var str="Hello World!"
document.write(str.length);//Output 12
</script>
3.substr() method, used for string intercept, a required parameter, an optional parameter, counting from 0
The code copy is as follows:
<script type="text/javascript">
var str="Hello World!"
document.write(str.substr(3));//Output lo World!, starting with characters with ordinal number 3 (including characters with ordinal number 3), and when there is only one parameter, it will be output to the end
document.write(str.substr(3,7));//Output lo World. If the first parameter is a negative number, it is a reverse number.
</script>
4.charAt() method is used to return characters at the specified position and count from 0.
The code copy is as follows:
<script type="text/javascript">
var str="Hello World!"
document.write(str.charAt(1));//Output e
</script>
5.split() method, used to split a string into a string array
The code copy is as follows:
<script type="text/javascript">
var str="Hello World!"
document.write(str.split(" "));//Output Hello,World!
document.write(str.split(""));//Output H,e,l,l,o,W,o,r,l,d,!
document.write(str.split(" ",1));//Output Hello
"2:3:4:5".split(":")//It will return ["2", "3", "4", "5"]
"|a|b|c".split("|")//It will return ["", "a", "b", "c"]
var words = sentence.split(//s+/)//Use regular expressions as split parameters
</script>