Home >Web Front-end >JS Tutorial >How to use split function in js to split a string according to multiple characters_javascript skills
The example in this article describes how js uses the split function to split a string according to multiple characters. Share it with everyone for your reference. The specific analysis is as follows:
The split() function in js can split the string according to the specified symbols, but if there are multiple splitting symbols in the string, is the split() function of js still competent? The answer is yes, js The split() function can achieve multi-delimiter string splitting through regular expressions. The call is also very simple. The following is a detailed example.
The following code can use the js split method to split the string according to commas
var mystring = "a,b,c,d,e"; var myarray = mystring.split(",");
If there is such a string: "jb51.net,google.com,baidu.com_weibo.com_haotu.net",
We want to split the website address according to commas and underscores at the same time, refer to the following code:
var mystring = "jb51.net,google.com,baidu.com_weibo.com_haotu.net"; var myarray = mystring.split(/[,_]/);
I hope this article will be helpful to everyone’s JavaScript programming design.