JavaScriptSplit () method_javascript skills

Source: Internet
Author: User
The split () method can split the string into a String Array Using the character string as the separator and return this array. This article introduces the javascriptsplit method, if you are interested in this article, learn it together. Definition and usage of the split () method:

The split () method can use the sub-string of the string as the separator to split the string into a string array and return this array.

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

This section only describes how to use common characters as separators. For more information about using regular expressions as separators, see section 1 of the Regular Expression split () function.

Click to see more related String object methods and attributes.

Syntax structure:

The Code is as follows:


StringObject. split (separator, limit)

Parameter List:

Parameters Description
Separator Required. The substring used to split the string.
Note: If this parameter is an empty string "", each character in the stringObject will be split.
Limit Optional. Sets the number of times the string is split. If this parameter is omitted, the number of splits is not limited.

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

Limit is optional. Sets the number of times the string is split. If this parameter is omitted, the number of splits is not limited.

Instance code:

The Code is as follows:


Var a = "a, B, c, d, e ";
Console. log (a. split (","));

Use the substring "," as the separator to separate the string. This separator does not become part of an array element or a member of an array element. Output result: a, B, c, d, e.

The Code is as follows:


Var a = "a, B, c, d, e ";
Console. log (a. split (",", 2 ));

Limit the number of times the string is split, that is, limit the number of dimensions of the returned array. Output result: 2.

The Code is as follows:


Var a = "a, B, c, d, e ";
Console. log (a. split (""));

If an empty string is used as the separator, each character in the string is separated. Output result: a, B, c, d, and e.

The above content is a small part of the knowledge about the JavaScript Split () method, I hope you like it.

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.