
How to split the string into array?

<html>
<head>
<title></title>
<script type="text/javascript">
var str = "Hello this is roseindia world";
var stringArray = new Array();
stringArray = str.split(" ");
for (i = 0; i < stringArray.length; i++) {
document.write("<br /> Array[" + i + " ]= " + stringArray[i]);
}
</script>
</head>
</html>
Description: The split() method is used to split a string into an array of substrings, and returns the new array. var stringArray = new Array(); here you declare new array of name stringArray. stringArray = str.split(" "); here you splitting the str and storing the value into stringArray. Now by using for loop you can easily print the array of split value of str.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.