Languages
[Edit]
EN

JavaScript - array slice() vs splice()

0 points
Created by:
Ela-Davey
663

In this article, we would like to show you the difference between array slice() and splice() methods in JavaScript.

 

slice()splice()
slice() doesn't change the original arraysplice() changes the original array

Syntax:

Syntax:

slice() method returns the selected elements in an array, as a new arraysplice() method returns items removed from an array
slice() method without arguments can be used to copy the whole arraysplice() method with three or more arguments can be used to remove some items and insert new ones.

 

Practical examples

Edit

In this example, we present how slice() and splice() methods affect array.

1. slice()

Edit

2. splice()

Edit

 

References

Edit
  1. Array.prototype.slice() - JavaScript | MDN
  2. Array.prototype.splice() - JavaScript | MDN

Alternative titles

  1. JavaScript - difference between array slice() and splice() method
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join