-
|
In short |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
When you use each one is up to you. If you have to alter the content of the array, |
Beta Was this translation helpful? Give feedback.
-
|
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. |
Beta Was this translation helpful? Give feedback.
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