Home > Article > Web Front-end > Several commonly used JavaScript string processing functions - split(), join(), substring() and indexOf()_javascript tips
Function: split()
Function: Use a specified delimiter to split a string and store it in an array
Example:
str="jpg|bmp|gif| ico|png";
arr=theString.split("|");
//arr is a string containing the character values "jpg", "bmp", "gif", "ico" and "png" Array
Function: John()
Function: Combine an array into a string using the delimiter of your choice
Example:
var delimitedString=myArray. join(delimiter);
var myList=new Array("jpg","bmp","gif","ico","png");
var portableList=myList.join("|");
//The result is jpg|bmp|gif|ico|png
Function: substring()
Function: String interception, for example, you want to get it from "MinidxSearchEngine" "Minidx" requires substring(0,6)
Function: indexOf()
Function: Returns the subscript of the first character matching the substring in the string
var myString="JavaScript";
var w=myString.indexOf("v");w will be 2
var x=myString.indexOf("S");x will be 4
var y=myString.indexOf("Script");y will also be 4
var z=myString.indexOf("key");z will be -1