JavaScript Reference/Javascript Methods/slice

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

"slice()" Example

    
<html>
<body>
<button onclick="var myS = new String("Sample String"); 
                 alert(myS.slice(4,7));">SLICE STRING</button>
<button onclick="var myA = new Array(10,11,12,13,14,15); 
                 alert(myA.slice(1,3));">SLICE ARRAY</button>
</body>
</html>



"slice()" is applied to

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



"slice()" Syntax, Parameters and Note

Note:
Returns a part of an Array or String object.
    
Syntax:
    
objectName.slice(param1, param2)
Parameters:
    param1   Required; starting character of a string or starting element of an array.
    param2   Required; ending character of a string or ending element of an array.