Guide to the use of split functions in Javascript

Source: Internet
Author: User

If you are familiar with the use of the split function in Javascript, I will share with you here. I believe this article will certainly help you gain some benefits.

Use of the split function in Javascript

Example of splitting a string using the split function in javascript:

 
 
  1. <script>  
  2.  alert("c:wwwccvita.jpg");   
  3.  var path="c:wwwccvita.jpg";  
  4.  var arr=path.split("");  
  5.  alert(arr);  
  6. </script> 

The following describes the split function:

Split Method

Splits a string into substrings and returns the result as a string array.

StringObj. split ([separator [, limit])

Parameters

StringObj

Required. String object or text to be decomposed. This object will not be modified by the split method.

Separator

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

Optional. This value is used to limit the number of elements in the returned array.

Description

The result of the split method 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.

Example

The following example demonstrates the use of the split function.

 
 
  1. FunctionSplitDemo (){
  2. Vars, ss;
  3. Vars = "TheraininSpainfallsmainlyintheplain .";
  4. // Separate each space character.
  5. Sss = s. split ("");
  6. Return (ss );
  7. }

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.