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?
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?
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"]
<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>
The following code snippet returns an array object:
"santhosh".split('') // s,a,n,t,h,o,s,h
You can use the following function:
string.split(separator, limit)
-just give the seperators as "" , it will split all charactors in the string.