JavaScript

slice/splice in JavaScript

JavaScriptArraysslice and splicebeginner

What this snippet does

slice returns a new array and never mutates; splice modifies the array in place and returns removed elements.

Expected output

[ 2, 3, 4 ]
[ 1, 2, 3, 4, 5 ]
[ 1, 99, 100, 4, 5 ]
[ 1, 2, 3, 4, 5 ]

Why practise typing this

Typing arrays code builds muscle memory for the symbols and indentation JavaScript uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More JavaScript practice

Browse all JavaScript snippets →