Example 1 — Extract a Range (End Exclusive)
Take fruits from index 1 up to (not including) index 4.
const fruits = ["apple", "orange", "banana", "grape", "kiwi"];
const middle = fruits.slice(1, 4);
console.log(middle);
// ["orange", "banana", "grape"] How It Works
- Pick the start. Index
1is"orange"— included. - Walk forward. Indexes
2and3are copied next. - Stop before end. Index
4("kiwi") is excluded becauseendis exclusive. - New array only.
middleis a fresh list;fruitsis untouched.

