← All free resources

FREE JAVASCRIPT ARRAY TOOL

Slice vs splice.
See what stays.

Same array. One letter apart. Predict what comes back and what gets left behind with this slice-versus-splice visualizer.

slice(start, end) copies a range; the end index is excluded. splice(start, deleteCount, ...items) edits the original and returns the removed elements. Its second argument is a count, not an end index.

2. Predict both values. 3. Reveal the difference.

Original array · before

index 0pinkindex 1purpleindex 2yellowindex 3blue

Indexes start at 0. Each snippet below starts with its own fresh array.

slice(1, 3)

Copy a range

Second argument: end index (excluded)

const colors = ["pink","purple","yellow","blue"];
const result = colors.slice(1, 3);
console.log(result);
console.log(colors);
Predict both console.log values

splice(1, 3)

Edit in place

Second argument: delete count

const colors = ["pink","purple","yellow","blue"];
const result = colors.splice(1, 3);
console.log(result);
console.log(colors);
Predict both console.log values

Choose a returned array and an original-after array for each snippet to unlock the reveal.

Free, no signup. These are fixed teaching examples, not a code runner. Predictions stay in this page’s memory only; reloading clears them. The examples use strings; slice copies are shallow, not deep copies of nested objects.

PUT YOUR NEXT AHA TO WORK

Try it in a short puzzle

Keep the return value and the original separate as you read.

Method references: MDN slice and MDN splice.