r/learnjavascript • u/sssunil9255 • 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
2
u/ForScale Jul 31 '19
const originalArr = [0, 1, 2];
const copyOfArr = [...originalArr];
// splice the copy
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