How to Use the split function in JavaScript

Source: Internet
Author: User
In JavaScript, the split function divides a string into substrings and returns the result as a string array. Usage: stringObj. split ([separator [, limit]) Where stringObj is required. String object or text to be decomposed. This object will not be modified by the split method. Separator is optional. In JavaScript, the split function divides a string into substrings and returns the result as a string array. Usage: stringObj. split ([separator [,
Limit])
StringObj is required. String object or text to be decomposed. This object will not be modified by the split method.
Separator is optional. A string or regular expression object that identifies whether a string is separated by one or more characters. If this option is ignored, a single array of elements containing the entire string is returned.
Limit is optional. This value is used to limit the number of elements in the returned array.

The result of the split function is a string array. In stingObj, the position where separator appears must be decomposed. The separator is not returned as part of any array element.

The following example demonstrates the use of the split function in JavaScript.

Function SplitDemo (){
Var s, ss;
Var s = "The rain in Spain falls mainly in theplain .";
// Separate each space character.
Ss = s. split ("");
Return (ss );
}

Related Article

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.