• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » JScript » String » JavaScript String split() Method
Next →
← Prev

JavaScript String split() Method

By Dinesh Thakur

JavaScript String split() Method: A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data streams. An example of a delimiter is the comma character, which acts as a field delimiter in a sequence of comma-separated values; each of the substrings is an element in the list.

For instance, the following string has three elements separated by commas:

“First element, Second element, Third element”

The string object provides the JavaScript Split Method, which you can use to split a string into elements at a specified delimiter. These elements are then placed in an array, and that array is returned by the method.

For instance, consider the following example of JavaScript Split Method:

var thisVar = "First element,Second element,Third element"; 
var anotherVar = thisVar.split(","); 

anotherVar is now an array containing three elements.

The following task illustrates JavaScript Split Method this by splitting a string containing a list into its component elements and then outputting those elements from the resulting array:

1. Open a new HTML document in your preferred HTML or text editor.

2. Create the body of the document with opening and closing body tags:

<body>
</body> 

3. Insert a script block in the body of the document:

<script language="JavaScript"> 
<!--// 
--> 
</script> 

4. Create a variable named myVariable and assign a comma separated text string to it:

var myVariable = "a,b,c,d"; 

5. Use the JavaScript Split Method to split the string at the commas and assign the resulting array to the variable stringArray:

var stringArray = myVariable.split(","); 

6. Use the document.write method to output the elements of the array so that the final script looks like

<body>  
<script language="JavaScript">  
<!--  var 
   myVariable = "a,b,c,d";  
    var stringArray = myVariable.split(",");  
   document.write(stringArray[0]);  
   document.write(stringArray[1]);  
   document.write(stringArray[2]);  
   document.write(stringArray[3]);  // -->  
</script>  
</body> 

7. Save the file and close it.

8. Open the file in a browser, and you should see the text “abcd”,

You’ll also like:

  1. Python String split() Method
  2. JavaScript String substring() Method
  3. JavaScript String substr() Method
  4. JavaScript String search() Method
  5. JavaScript String match() Method
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

JavaScript Tutorials

JavaScript Tutorials

  • JavaScript - Home
  • JavaScript - Operators
  • JavaScript - Comments
  • JavaScript - If...Else
  • JavaScript - For Loop
  • JavaScript - Popup Boxes
  • JavaScript - Switch Statement
  • JavaScript - while Loop
  • JavaScript - Functions
  • JavaScript - Variables
  • JavaScript - Statements
  • JavaScript - Substring()
  • JavaScript - indexOf()
  • JavaScript - Match()
  • JavaScript - Replace()
  • JavaScript - Search()
  • JavaScript - Split()
  • JavaScript - Substr()
  • JavaScript - Blink()
  • JavaScript - Anchor()
  • JavaScript - Big()
  • JavaScript - Strings Object
  • JavaScript - String Format
  • JavaScript - Length Property
  • JavaScript - Prototype
  • JavaScript - Slice Substr Vs Substring
  • JavaScript - JavaScript:void(0)

Other Links

  • JavaScript - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW