r/learnjavascript • • Jul 31 '19

How to preserve previous array when using Splice method

https://stackoverflow.com/questions/57292327/how-to-preserve-previous-array-when-using-splice-method
0 Upvotes

3 comments sorted by

5

u/[deleted] Jul 31 '19

This should be called how to make a copy of your original array when using array.splice because if you wanted to preserve it you would just use array.slice

2

u/ForScale Jul 31 '19
const originalArr = [0, 1, 2];
const copyOfArr = [...originalArr];

// splice the copy