List.splice method

Removes elements from a list and, if necessary, inserts new elements in their place, returning the deleted elements.


var array = list.splice(start, howMany, item);


  • start
    Type: Number

    The zero-based location in the list from which to start removing elements.

  • howMany
    Type: Number

    The number of elements to remove.

  • item
    Type: Object

    The elements to insert into the list in place of the deleted elements.

Return value

Type: Array

The deleted elements.


The following code shows how to use this method.

<div id="splicedList"></div>
<div id="deletedList"></div>
<script type="text/javascript">
    var myList = new WinJS.Binding.List(["Tom", "Sam", "Bill"]);

    // Remove two items starting from index 1 and replace with "Sally".
    var deletedItems = myList.splice(1, 2, "Sally");

    document.getElementById("splicedList").textContent = "After splicing, the list contains: ";
    var i = myList.length;
    while (--i >= 0)
        document.getElementById("splicedList").textContent += myList.getItem(i).data + " ";

    document.getElementById("deletedList").textContent = "Deleted items are: ";

    var j = deletedItems.length;
    while (--j >= 0)
        document.getElementById("deletedList").textContent += deletedItems[j] + " ";

// Output: 
// After splicing, the list contains: Sally Tom
// Deleted items are: Bill Sam


Minimum WinJS version

WinJS 1.0



See also