- String_Object: Please specify the valid string on which you want to perform Splitting.
- Limit: Please specify the integer number. This argument will restrict the number of elements written by the array.
- If you omit the second index then, JS string Split function will start from the beginning and continue till end.
The following set of examples will help you understand the string Split function.
In this JS split string function example, First, we declared the String variable Str1 and assigned corresponding value using following statement
var Str1 = "We are Abc working in abc company since abc years";
The following JS string split statement will split the original string into individual characters
var Str2 = Str1.split("");
var Str3 = Str1.split(" ");
Next, We used the second argument to restrict the array output to four.
var Str4 = Str1.split(" ", 4);
Next, We used substring “abc” as separator for the Js Split string function. Here i is the regular expression to perform case insensitive search
var Str5 = Str1.split(/abc/i);