Array.splice() : Splice « Array « JavaScript Tutorial

Home
JavaScript Tutorial
1.Language Basics
2.Operators
3.Statement
4.Development
5.Number Data Type
6.String
7.Function
8.Global
9.Math
10.Form
11.Array
12.Date
13.Dialogs
14.Document
15.Event
16.Location
17.Navigator
18.Screen
19.Window
20.History
21.HTML Tags
22.Style
23.DOM Node
24.Drag Drop
25.Object Oriented
26.Regular Expressions
27.XML
28.GUI Components
29.Dojo toolkit
30.jQuery
31.Animation
32.MS JScript
JavaScript Tutorial » Array » Splice 
11.30.1.Array.splice()

Syntax

array.splice(start,delete,arg3,...,argN)

start -- The position in the array where the slice is to begin.

delete -- The number of elements to be deleted from the array, beginning at the position specified by start.

arg3,...,argN -- New array elements to be inserted into the array, starting at the position specified by start.

Returns -- If any elements are deleted from the array, they are returned from the method as an array.

The splice() method can either add elements to or delete elements from an array.

When the delete parameter contains a number other than zero, the elements beginning at start and ending at index start+ending are deleted from the array.

If delete is zero, no elements are deleted.

All elements from start to the end of the array are deleted when delete is not specified.

If arguments follow the delete parameter, they are added to the array as elements beginning at the position specified by start.

Existing elements are shifted up to allow room for the new elements.

<html>
    <script language="JavaScript">
    <!--
    function printOrder(theArray)
    {
      document.write("The current order is:<br>");
      for(i=0; i<theArray.length; i++)
      {
        document.write("- ",theArray[i],"<br>");
      }
    }

    myArray = new Array("A","B","C");
    document.write("<h3>The initial order taken</h3>");

    printOrder(myArray);

    myArray.splice(0,1,"D");
    printOrder(myArray);
    -->
    </script>
    </html>
11.30.Splice
11.30.1.Array.splice()
11.30.2.Using the splice() method of the Array object
11.30.3.Using the splice() method to replace elements
11.30.4.Using the splice() method to insert elements
11.30.5.Using splice method from zArray Library
11.30.6.Using splice method from zArray Library 2
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.