JavaScript · Junior · Question 26 of 75

How does slice differ from splice?

Explanation

arr.slice(1, 3) creates a new array. arr.splice(1, 2, 'x') removes and inserts elements in arr itself. The non-mutating alternative is toSpliced(). Other mutating methods: push, pop, shift, sort, reverse.

Further reading

Problem with a question

JavaScript · Junior · question 26

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz