JavaScript Reference/Javascript Methods/slice

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

"slice()" Example

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

"slice()" is applied to

| Applied_To     |Array                           String                        |

"slice()" Syntax, Parameters and Note

Returns a part of an Array or String object.
objectName.slice(param1, param2)
    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.