SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Javascript Tutorials and Javascript Frameworks jQuery resources, tools, articles, code samples and downloads for Web Programmers


Javascript String Split Function Example and Javascript Split Function Tutorial


In Javascript, developers can easily handle string split using javascript split function using the String object in a given text or string variable.

The Javascript string SPLIT function takes only one parameter as an argument which identifies the delimeter character.
This method parameter in javascript Split function is the delimeter char which splits the given string text into pieces.
The delimeter parameter is not a part of any splitted pieces.





Javascript Split Function Example - 1

Below you can find a Javascript string split function example which is displaying the basics how can javascript developers can use the string split function.
This split example will split a sentence into words by using javascript string split method with the space character as the delimeter parameter.
The splitted words will be stored as an array of string values as the result of javascript split function.

var str = "This is Javascript String Split Function example";

var stringSplitArray = str.split(" ");

var j = 0;
for(j = 0; j < stringSplitArray.length; j++){
  alert(stringSplitArray[j]);
}
Code

Javascript Split Function Example - 2

An other example of Javascript split function is splitting comma "," seperated text into pieces.
Let's assume that this string split example is used on a web page where a list of checkbox items exist on the web page and we are storing the checked checkbox item values as a concatenated string.
When we submit the checked list of items, we are required to split the concatenated values into single values by using the javascript string split function as follows;

var str = "3,6,12,19,26,33,72";

var checkedItemsArray = str.split(",");

var j = 0;
for(j = 0; j < checkedItemsArray.length; j++){
  alert(checkedItemsArray[j]);
}
Code

I hope in this short javascript tutorial, you have found the basics of using Javascript Split function in javascript codes where you are required to split string using Javascript.



Javascript


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.