Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
slice returns a shallow copy of a selected range without mutating the source. splice changes the source and returns removed items.
For const a = [1, 2, 3, 4], a.slice(1, 3) returns [2, 3] and leaves a unchanged; the end index is exclusive. a.splice(1, 2, 9) removes two items starting at index 1, inserts 9, returns [2, 3], and leaves a as [1, 9, 4]. The second splice argument is a delete count, not an end index.