Separating text with javascript

Hi, I have a line called "santhosh". I want to break this text as 's, a, n, t, h, o, s, h' using javascript. Is it possible? And you want to save it in an array.

And I want to check if the split character is string or numeric, is this possible?

+3
source share
4 answers

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

var array = "santhosh".split('');
// ["s", "a", "n", "t", "h", "o", "s", "h"]
+6
source
<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>
+1
source

:

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

:

string.split(, )

- "", .

+1

Source: https://habr.com/ru/post/1730509/


All Articles