JavaScript Reference/Javascript Methods/split

Материал из Web эксперт
Перейти к: навигация, поиск

"split()" Example

   <source lang="javascript">
   

<html> <body> <script language="javascript"> function function1(){

  var myString = "Sample String 1 2 3";
  var myArray = myString.split(" ");
  alert(myArray.length);

} </script> <button onclick="function1();">SPLIT</button> </body> </html>


     </source>
   
  


"split()" is applied to

   <source lang="javascript">

+----------------+--------------------------------------------------------------+ | Applied_To |String | +----------------+--------------------------------------------------------------+

     </source>
   
  


"split()" Syntax, Parameters and Note

   <source lang="javascript">

Note: Uses the specified delimiter to split the String into an array of String.

Syntax:

stringName.split(param1, param2) Parameters:

   param1   Required; the delimiter to use.
   param2   Optional; the maximum number of elements to return in the array.
   
     
     </source>