|
| |
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> "));
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|