what is difference between splice and slice in javascript method

what is difference between splice and  slice in javascript method
in this article, i will show you, difference between splice and  slice in javascript method

diff(1)

-splice() method adds/removes items to/from an array ,and returns the removed items.
-slice()   method returns the selected elements in an array,as a new array object.

diff(2)

-splice() method changes the original array but slice method doesn't.

diff(3)

-splice() method can take n number of arguments
-slice()   method takes 2 arguments

examples:

var list=['a','b','c','d','e'];

// array.slice(startindex, endindex-1)
console.log(list.slice(1,3));
// ["b,c"]

//array.splice(startindex, endindex(count))
console.log(list.splice(1,3));
// ["b","c","d"]

Post a Comment

0 Comments