JavaScript Reference/Javascript Methods/split

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

"split()" Example

    
<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>



"split()" is applied to

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



"split()" Syntax, Parameters and Note

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.