str="2,2,3,5,6,6"; //This is a string
var strs= new Array(); //Define an array
strs=str.split(","); //Character Split
for (i=0;i<strs.length ;i++ )
{
document.write(strs[i]+"<br/>"); //The split character output
}
The output is 2 2 3 5 6 6
js split is to split a string into multiple strings with specific characters
The split() method splits a string into an array of strings
If an empty string ("") is used as the separator , then each character in the stringObject will be split.
slice()
returns the selected element from the existing array
Object.slice(start,end)
var arr=[1,2,3,4,5]
console.log(arr.slice(0,3))
/ /1,2,3
Substring()
function: String interception, for example, if you want to get "Minidx" from "MinidxSearchEngine", you need to use it
substring(0,6)) var str = "0123456789"; alert(str.substring(0));------------"0123456789" alert(str.substring(5));------------"56789" alert(str.substring(10));-----------"" The output is respectively;------------"0123456789" ------------"56789" ------------""
The charAt() method returns the character at the specified position
Truncate the first charactervar str="Hello world!" console.log(str.charAt(1)) The output is e
concat()
concatenates two arrays together;
arr1 = [1,2,3,4]
arr2=[5,6,7,8]
console.log(arr1.concat(arr2))
//The result is [1,2,3,4,5,6,7,8]