How to Use the split function in js

Source: Internet
Author: User

Split
Split is opposite to join, used to split a string into a string array.
StringObject. split (a, B) is its syntax.

A is a required decision to separate from.
B is not required. Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings are returned than the array specified by this parameter. If this parameter is not set, the entire string is split, regardless of its length.

Note that the returned array does not include a itself;

Tips and comments
NOTE: If an empty string ("") is used as a, each character in the stringObject is separated.
Note: The operations executed by String. split () are the opposite to those executed by Array. join.

Example
Var str = "Hello World! ";
Document. write (str. split ("") + "<br/> ");
Document. write (str. split ("") + "<br/> ");
Document. write (str. split ("", 3) + "<br/> ");

Return
H, e, l, l, o, W, o, r, l, d ,!
Hello, World!
H, e, l

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.