String Split function in JavaScript split usage example

Source: Internet
Author: User

This article mainly introduces the string split function in JavaScript, split usage, the example of the split function in JavaScript to manipulate the string of skills, very practical value, the need for friends can refer to the next

This example describes the split usage of the string split function in JavaScript. Share to everyone for your reference. Specific as follows:

First look at the following code:

<script type= "Text/javascript" >var str= "How is you doing today?" document.write (Str.split ("") + "<br/>") document.write (Str.split ("") + "<br/>") document.write (Str.split ("", 3))</script>
The output results are as follows:
How,are,you,doing,today? H,o,w,, A,r,e,, Y,o,u,, D,o,i,n,g,, T,o,d,a,y,? how,are,you
Example:
// will return ["2", "3", "4", "5"] // will return ["", "a", "B", "C"]

Use the following code to divide the sentence into words:

var words = Sentence.split (")
If you want to divide the word into letters or divide the string into characters, you can use the following code:
// can return ["H", "E", "L", "L", "O"]
To return only a subset of characters, use the Howmany parameter:
"Hello". Split ("", 3)  // can return ["H", "E", "L"]
or use regular expressions as separator:
var words = Sentence.split (/\s+/)
Hopefully this article will help you with JavaScript programming.

String Split function in JavaScript split usage example

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.