DEV Community

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

Posted on

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

โค๏ธ๐Ÿ’™