array slice methods in javascript code example
Example 1: javascript slice array
const FRUITS = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = FRUITS.slice(1, 3);
var fromTheEnd = FRUITS.slice(-3, -1);
Example 2: slice in javascript
JavaScript Array slice() Method The slice() method returns the selected elements in an array, as a new array object. The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. Note: The original array will not be changed.