Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Splice method in javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    The splice() method is used to add/remove items to/from an array, and returns the removed item(s).

    Syntax

    array.splice(index, howMany, [element1][, ..., elementN]);

    where

    index Index at which to start changing the array.

    howMany An integer indicating the number of old array elements to remove. If howMany is 0, no elements are removed.

    element1, ..., elementN The elements to add to the array. If you don't specify any elements, splice simply removes the elements from the array.

    Example:

    var arr = ["one", "two", "three", "seven", "ten"];
    
             var removed = arr.splice(2, 0, "eleven");
             document.write("After adding 1: " + arr );
             document.write("<br />removed is: " + removed);
    
             removed = arr.splice(3, 1);
             document.write("<br />After adding 1: " + arr );
             document.write("<br />removed is: " + removed);
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: