Difference between split and join in javaScript (detailed description), splitjoin

Source: Internet
Author: User

Difference between split and join in javaScript (detailed description), splitjoin

Common features: the split and join functions are usually operations on characters or strings;

Differences between the two:

(1) split () is used to split a string and return an array,

For example

Var string = "hello world? Name = xiaobai ";

Var splitString = string. split ("? ");

Console. log (splitString); // ["hello world", "name = xiaobai"]

Split () has only one parameter: The split string or regular expression. When two parameters are used, the second parameter indicates the number of elements in the returned array;

(2) join () is used to connect multiple characters or strings. the return value is a string;

For example

Var arr = new Array ();

Arr [0] = "hello ";

Arr [1] = "xiao ";

Arr [2] = "bai ";

Arr. join ("&"); // "hello & xiao & bai"

Join (); // The default Delimiter is comma;

The difference between split and join in the above javaScript section (detailed description) is all the content shared by the editor. I hope to give you a reference and support for the customer's house.

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.