Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The Array.splice() Method

    If I get it right, the splice method only works if all of the indexes in the array are numerical values? (i.e. 0, 1, 2, 3, ...)

    I tried using it when the indexes were strings, not numbers - and it didn't work:

    [highlight="javascript"]
    var x = new Array();
    x['one'] = 'a;
    x['two'] = 'b';
    x['three'] = 'c';
    x['four'] = 'd';

    x.splice('two', 1);

    for (i in x)
    {
    document.write(x[i] + '<br />');
    }
    </scr[/highlight]

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,795
    Thanks
    19
    Thanked 156 Times in 147 Posts
    Definition and Usage
    The splice() method is used to remove and add new elements to an array.

    Syntax
    arrayObject.splice(index,howmany,element1,.....,elementX)

    1) index - Required. Specify where to add/remove elements. Must be a number
    2) howmany - Required Specify how many elements should be removed. Must be a number, but can be "0"
    3) element1 - Optional. Specify a new element to add to the array
    4) elementX - Optional. Several elements can be added
    Last edited by chump2877; 05-04-2007 at 04:01 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •