DEV Community

loading...
Cover image for Javascript Splice Vs Slice

Javascript Splice Vs Slice

itsmukulmishra profile image Mukul Mishra ใƒป1 min read

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 ๐Ÿค๐Ÿ‘Œ

Discussion

pic
Editor guide
Collapse
ayaofficielle profile image
ayaofficielle

โค๏ธ๐Ÿ’™