Make an array from string in javascript | Web Programming Tutorial

Make an array from string in javascript

Published Date: November 7, 2013 |
Published Time: 9:30 pm |

Sometime we need to make an array from a specific string in javascript such as for count total word,or spliting the word for various reason. To do this javascript provides a methods called split() method.

Syntax of split method : string.split(separator,limit)

These two parameters are optional.

Ok, now we will see how this method works:

write this code at top of the page or any where in javascript tage.

Here the string will be splited by space (” “).

and output will like :


Now we can use the char_array  variable as an array. where the value is located like [0]=>’Hello’, [1]=>’this’,[2]=>is,[3]=>’a’ …………………..

so if we use char_array[2] then we will get  “is

See details about split method : split()

Leave a Reply

Your email address will not be published. Required fields are marked *