
How to split string into words using javascript?

<html>
<head>
<title></title>
<script type="text/javascript">
var str="Hello this is roseindia world.";
document.writeln(str.split(" "));
</script>
</head>
</html>
Description: The split() method is used to split a string into an array of substrings, and returns the new array. Two parameter (separator, limit) is used in it, which is optional. separator specifies the character which is used for splitting the string. If you don?t put any separator then split() method will return entire string.limit is an integer value, used to specify the number of splits.
str.split() ? it returns the whole str value.
Str.split(" ")- it split the str by finding the space. That is split str into words.
Str.split("")-it split str into character.
Str.split(" ",3)-split in word and return first 3 words.