Home > Web Front-end > JS Tutorial > How to use split function in js to split a string according to multiple characters_javascript skills

How to use split function in js to split a string according to multiple characters_javascript skills

WBOY
Release: 2016-05-16 16:08:28
Original
1877 people have browsed it

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(",");
Copy after login

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(/[,_]/);
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template