English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
slice()The method extracts a part of the array elements and returns a new array.
slice()The method extracts elements starting at the givenstartParameters, and at the given endendParameters (endDoes not include). The original array is not changed.
array.slice(start, end)
var fruits = ["39;Banana', 'Mango', 'Apple', 'Orange'); var extract = fruits.slice(1, 3);// return Mango, AppleTest and see‹/›
The numbers in the table specify the first browser version fully supporting the slice() method:
Method | |||||
slice() | 1 | 1 | Is | Is | Is |
Parameter | Description |
---|---|
start | (Optional) Starting index, from this index extraction begins |
end | (Optional) Starting index, before the extraction ends |
Return value: | New array containing the extracted elements |
---|---|
JavaScript Version: | ECMAScript 1 |
withoutendParameter to extract elements:
var fruits = ["39;Banana', 'Mango', 'Apple', 'Orange'); var extract = fruits.slice(1);// return Mango, Apple, OrangeTest and see‹/›
Extract elements using negative values:
var fruits = ["39;Banana', 'Mango', 'Apple', 'Orange'); var extract = fruits.slice(-3, -1);// return Mango, AppleTest and see‹/›