- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Low level difference between Slice and Splice methods in Javascript
The basic difference between slice and splice is −
splice() changes the original array on which it is called and returns the removed item(s) in an array as a new array object.
slice() doesn't change the original array and also returns the array sliced.
Example
// splice changes the array let arr = [1, 2, 3, 4, 5]; console.log(array.splice(2)); //slice doesn't change original one let arr2 = [1, 2, 3, 4, 5]; console.log(array2.slice(2)); console.log("
After Changing the arrays"); console.log(array); console.log(array2);
Output
[ 3, 4, 5 ] [ 3, 4, 5 ]
After Changing the arrays
[[ 1, 2 ] [ 1, 2, 3, 4, 5 ]
Advertisements
To Continue Learning Please Login
Login with Google