JavaScript Split function

Source: Internet
Author: User

Being able to split into a series of separate blocks has been supported in many programming languages, and it can be in JavaScript as well. If you have a long list of names, such as "Bobysu Santresideni" and you want each store to be named separately, you can specify the space character "" and have the split feature create a new chunk each time you see the space.


Split function: Separating
Space nature "," what we mentioned would be our separation and use it to break the string with its split function. Each time we see the partition we specify, a new element will be created, an array. The split function of the first parameter is delimited.

A simple example of a split function
Let's first close the small example, take a series of numbers and split when you see the number 5. This means that the separation for this example is 5. Notice that the Split function returns an array of our stores to Mysplitresult.

<script type= "Text/javascript" >
var myString = "123456789";

var mysplitresult = Mystring.split ("5");

document.write ("The" the "the" + mysplitresult[0]);
document.write ("<br/> The second element is" + mysplitresult[1]);
</script>

Results.

The 1234
The second element is 6789

Be sure to recognize that because we chose 5 to be our separation, this is not in line with our results. This is because the separation is from the string, the rest of the character divides the space used by the 5 occupation.

to magnify the Split function example
below, we have established a split example to illustrate how this function is different from many. We have established a string number of words through four zeros. Delimited in this example will be the space character "".

<script type= "Text/javascript"
var myString = "Zero One Two three";

var Mysplitresult = Mystring.split ("");

for (i = 0; i < mysplitresult.length i++) {
document.write ("<br/> Element" + i + "=" + mysplitre Sult[i]);
}
</script>
results.

Element 0 = Zero
Element 1 = one
element 2 = two
element 3 = three
element 4 = four

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.