Best guide of split function in JavaScript

JavaScript is one of the most popular programming languages these days.
This language is popular because of its flexibility as well as versatility.
Here, we are focusing on a concept used in this language.
We are about to discuss split function of JavaScript.
The split function in JavaScript is used in order to split the substrings on the basis of regular expressions or else one the basis of its delimiter.
Here, we are going to give you the best guide to use split function in your programs.

What is Split function?

First of all, we are going to explain the concept of split function.
As we have mentioned above, you split string into the substrings.
In order to do so, you have to use specific separators.
As a result, you will get an array.
The major variants of this methodology are:
String[] split(String regex): By using this method, you will get an array of strings once you split the input string which is based on delimiting the regular expression.
String[] split(String regex, int limit): You will find only one difference between these two variations.
The difference is that it will limit the number of strings which are retuned after the split up.

Syntax of split function:

Following is the syntax of split function which you can use in your codes:

Parameters of split function:

  • StringObj: The first parameter of split function is required. Here, we would like to add that the object is not modified by the split method.
  • Separator: This is optional. This is a regular expression object which is used in order to identify the characters for the purpose of separating the string.
  • Limit: Limit is also optional. The role of limit is to limit the number of elements which are supposed to be returned in the array.


The following case demonstrates the use of the split method.

var s = " Every cloud has a silver lining. ";  
var ss = s.split(" ");  
for (var i in ss) {  
// Output:   
// Every 

Requirements for split function:

The split function is supported in the following modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards.
It is also supported in Store apps.
For instance: Windows 8 in addition to Windows Phone 8.1.



Boostlog is an online community for developers
who want to share ideas and grow each other.

Delete an article

Deleted articles are gone forever. Are you sure?