DEV Community

Cover image for Javascript Splice Vs Slice
D\sTro
D\sTro

Posted on

3 1

Javascript Splice Vs Slice

Splice vs Slice!

the most confusing method of javascript which can be understood easily. Hope this helps ⤵️

slice: copies array then operates
splice: doesnt copy array

slice is like you're creating multiple slices of 1 apple and splice I like you are making slices of apples itself

Let xArray = [1,9,9,2]  
Let yFuntion = (array) =>{  
    //slice the array  
}  
yFuntion(xArray)
Console.dir(xArray) : no effect

//=========  

Let zFuntion = (array) =>{
    //"splice" the array  
} 
zFuntion(xArray)
Console.dir(xArray) : affected

Enter fullscreen mode Exit fullscreen mode

Any other shortcut stuff you use for remembering these kind of method, share with us 🤝👌

Top comments (1)

Collapse
 
ayabouchiha profile image
Aya Bouchiha

❤️💙

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay