JavaScript String - split() Method

Description

This method splits a String object into an array of strings by separating the string into substrings.

Syntax

Its syntax is as follows −

string.split([separator][, limit]);

Argument Details

Return Value

The split method returns the new array. Also, when the string is empty, split returns an array containing one empty string, rather than an empty array.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript String split() Method</title>
   </head>
   
   <body>
   
      <script type="text/javascript">
         var str = "Apples are round, and apples are juicy.";
         var splitted = str.split(" ", 3);
         
         document.write( splitted );
      </script>
      
   </body>
</html>

Output

Apples,are,round,