Replies: 2 comments
|
When you use each one is up to you. If you have to alter the content of the array, |
0 replies
Answer selected by
montasim
|
Slice is used to get a new array from the original array whereas the splice is used to add/remove items in the original array. The changes are not reflected in the original array in the case of slice and in the splice, the changes are reflected in the original array. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
slicereturns a piece of the array but it doesn’t affect the original array.splicechanges the original array by removing, replacing, or adding values and returns the affected values.When you use each one is up to you. If you have to alter the content of the array,
spliceis the way to go, but if you just want to obtain a subarray,sliceshould be your choice