JavaScript Split () method _javascript Tips

Source: Internet
Author: User

Definition and usage of the split () method:

The split () method splits the string into an array of strings using the substring of the string as a delimiter, and returns the array.

Note: The substring as a delimiter does not become part of the element of the returned array or a member of the array element.

This only describes using ordinary characters as delimiters, and you can refer to the regular expression split () function section with regular expressions as delimiters.

Click to see more related string object methods and properties.

Syntax structure:

Copy Code code as follows:

Stringobject.split (Separator,limit)

Parameter list:

Parameters Describe
Separator Necessary. The substring used to split the string.
Note : If this parameter is an empty string "", then each character in the Stringobject will be split
Limit Optional. Sets the number of times the string is split, and if this argument is omitted, the number of splits is not limited.

Note: If this parameter is an empty string "", then each character in the Stringobject will be split

Limit optional. Sets the number of times the string is split, and if this argument is omitted, the number of splits is not limited.

Instance code:

Copy Code code as follows:

var a= "A, B, C, D, E";
Console.log (A.split (","));

Use the substring "," as the delimiter to split the string, which does not become part of an array element or a member of an array element. Output result: A,b,c,d,e.

Copy Code code as follows:

var a= "A, B, C, D, E";
Console.log (A.split (",", 2));

The number of times a string is delimited, which limits the number of dimensions that return an array. Output Result: 2.

Copy Code code as follows:

var a= "A, B, C, D, E";
Console.log (A.split (""));

With an empty string as the delimiter, each character in the string is split. Output result: a,、, b,、, c,、, d,、, E.

The above content is small to introduce the JavaScript Split () method of knowledge, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.