SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Creating arrays by using split method in a string

We have seen how to create string using elements of an array. Now we will see how to create an array from a string by using some delimiter. For this we will use split() method which works on a string and create array out of it. This is one of the method used to create an array. Here is the basic syntax for using split() method.

var array_name=string_variable.split(" ");


Here one space is used as delimiter for creating an array. Now let us use one string variable to store a sentence and create an array out this by using one space as delimiter in a split() method. Here is the complete code for this.

var str="this is my new tutorial";
var a1 = new Array();
a1=str.split(" ");
document.write(a1.join(" <br> "));





Further readings
Declaring array in JavaScript
Displaying elements of an array by looping through
join():Displaying elements of an array using join() function
sort():Sorting of elements of an array using function
length:Length property to get the total number of elements in an array
reverse():Reversing the elements of an array
pop():Removeing last element of an array by using pop()
shift():Removeing first element of an array using shift()
push():Adding elements to array using push()
unshift():Adding elements to array using unshift()
splice():Add replace remove elements from an array using splice()
split():Creating array by splitting string variable
toString: To join all elements and create a string
concat: To join two or more arrays to a single array
slice: To return element from an array with starting and ending positions
Two Dimensional Array: Adding and displaying elements




Join Our Email List
Email:  
For Email Newsletters you can trust
Array Functions