Skip to content

What is the difference between slice and splice? #345

Answered by d4tdev
montasim asked this question in Q&A
Discussion options

You must be logged in to vote

slice returns a piece of the array but it doesn’t affect the original array. splice changes 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, splice is the way to go, but if you just want to obtain a subarray, slice should be your choice

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by montasim
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants