slice()
noun
say it: “SLYSS” /slaɪs/
A JavaScript method that copies part of an array or string, from a start position up to (not including) an end position, and leaves the original alone.
What does slice() do in JavaScript?
slice() — A method that returns a selected portion without changing the original array or string.
const tasks = ["Plan", "Build", "Test"];
const selectedTasks = tasks.slice(1);
In a sentence
- “'Highway Sunrise'.slice(0, 7) gave me 'Highway'.”
- “scores.slice(0, 3) gave me the top three scores and left the full list in place.”
Level: Apprentice · More JavaScript terms at this level
Updated