tags:

views:

75

answers:

4

Hi I am having string called 'santhosh'. I wish to split this text as 's,a,n,t,h,o,s,h' using javascript. Is it possible? And want to save it in an array.

And I wish to check whether the splitted character is string or Numeric is it possible?

+6  A: 

You can use an empty string as the separator argument of the split method:

var array = "santhosh".split('');
// ["s", "a", "n", "t", "h", "o", "s", "h"]
CMS
i wish to store it in an array
susanthosh
The `split` method already returns an array.
CMS
split will return an array
rahul
Its working fine
susanthosh
thanks CMS. I got it
susanthosh
Now I wish to check whether the splitted character is string or Numeric is it possible?
susanthosh
If you want to check whether a single character is numeric, you could use something like:`/^\d$/.test(x)` where x is a variable that contains the character you want to test.
Tim Goodman
@susanthosh: If you want to ask a new question it's better to create a new question instead of adding comments to the original question.
Mark Byers
+1  A: 
<script type="text/javascript">
var myString = "Hello";

var mySplitResult = myString.split('');

document.write("The first element is " + mySplitResult[0]); 
document.write("<br /> The second element is  " + mySplitResult[1]); 
document.write("<br /> The third forth is  " + mySplitResult[2]);
document.write("<br /> The fourth element is  " + mySplitResult[3]);
document.write("<br /> The fifth element is  " + mySplitResult[4]);
</script>
Michel Kogan
+1  A: 

The following code snippet returns an array object:

"santhosh".split('') // s,a,n,t,h,o,s,h
bryantsai
+1  A: 

You can use the following function:

string.split(separator, limit)

-just give the seperators as "" , it will split all charactors in the string.

Mugunth