← TechnologyThe essentials of

slice(): copy of selected part

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The final index does not enter the copied part.

Useful to know

slice(start, end) returns a shallow copy of a part of an array without changing the original. For example, [10, 20, 30, 40].slice(1, 3) gives [20, 30]. The beginning is on, the end is not . [1]

For the first three items, use slice(0, 3), and not slice(0, 2). The method is convenient for previewing a list. If items are objects, internal objects remain shared: a new container does not mean an independent copy of each property. Do not mix slice with splice, which changes the array.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.slice ↗