3

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?

4 Answers 4

6

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"]
Sign up to request clarification or add additional context in comments.

4 Comments

i wish to store it in an array
Now I wish to check whether the splitted character is string or Numeric is it possible?
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.
@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.
1
<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>

Comments

1

The following code snippet returns an array object:

"santhosh".split('') // s,a,n,t,h,o,s,h

Comments

1

You can use the following function:

string.split(separator, limit)

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.