Javascript’s Splice

Javascript’s Splice

I recently spent a few hours trying to understand why my array was changing when using the splice method. I thought I’d save you some time and outline what I learned.

Still new to JS and struggling with the fundamentals? Check out Javascript: The Defenitive Guide (paid link) to brush up.

For Those of You Short on Time

Splice edits the original array!

// edit original array
x=[1,2,3]
x.splice(2)
console.log(x)
[1,2]

Leave a Comment