What is Splice & Slice method in Javascript

By
Splice & Slice Method in JavaScript

First I want to clear some point

 1. Slice() and Splice() are core JavaScript method.
 2. Both Sounds like same but both are different.
 3. Both use for Manipulate the Array.


Code Sample [All Html & Jquery]

Slice Method();

  1. Slice take two parameter where second one is optional.
  2. Both Parameter is integer type .
  3. First Parameter is where to use the selection & second is where to end the selection.
  4. Its copy the original Array and not modify the original Array
  5. Array starts from zero. So if you right down 1 in first parameter then its select second element of Array.
  6. If a single argument is given to the slice() method, the array returned will contain all elements from the start position to the end of array. 
  7. If you not pass any parameter and just call this then its copy the original array.If a negative value is supplied for either parameters, this means that the slice() will count the position from the end of the array, instead of the beginning. So please check for better understading.
 Splice Method();

  1. splice() method used for add or remove items from an array.
  2. splice take three parameter where third one is optional.
  3. First two Parameter is integer type and third one is any type .
  4. First Parameter is where to use the selection & second is number of elements to remove & third one is new elements to be added.
  5. It modify original Array
  6. Array starts from zero. So if you right down 1 in first parameter then its select second element of Array.
  7. If a single argument is given to the splice() method, the array remove all elements from the start position to the end of array. 
  8. Do self for better understading.
Output
Slice/Splice (Click Slice or Splice button) :-


Customize Output
Slice/Splice Start From :- Slice/Splice End :- Splice Optional Parameter :-
read more..

0 comments:

Post a Comment