JS uses split to split the string into an array instance summary

Source: Internet
Author: User
Tags regular expression

Definitions and usage

The split () method is used to split a string into an array of strings.

Grammar
Stringobject.split (Separator,howmany)

Parameter description

Separator required. A string or regular expression that splits the Stringobject from the place specified by the parameter.
Howmany Optional. This parameter specifies the maximum length of the array to return. If this argument is set, the returned substring will not be more than the array specified by this parameter. If this argument is not set, the entire string is split, regardless of its length.


cases

Split a string into groups using split

The code is as follows Copy Code

birthday= ' 1990-12-16 ';
Arr=birthday.split ("-");/use-Split date
arr[0]//1990
Arr[1]//12
Arr[2]//16


cases

The code is as follows Copy Code

<script language= "JavaScript" >
Str= "2,2,3,5,6,6"; This is a string
var strs= new Array (); Define an array

Strs=str.split (","); Character segmentation
for (i=0;i<strs.length; i++)
{
document.write (strs[i]+ "<br/>"); Character output after segmentation
}
</script>

Examples in my project:

  code is as follows copy code

function Selectcompany ()
   {
    var str= window.showModalDialog ("messageframe.htm", "", "dialogwidth=730px,dialogleft=400px,dialogtop=400px;center:yes; Status:no ");
   
    var str2=new Array ();
    str2=str.split ("|");
    var List1=document.getelementbyid ("Lstsendobjects");
    for (i=0;i<str2.length;i++)
    {
         List1.add (New Option (str2[i],str2[i));
   }
   
  }

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.