List.splice method

Applies to Windows and Windows Phone

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

Syntax


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

Parameters

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.

Examples

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", "Dick", "Harry"]);

    // 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] + " ";
</script>

// Output: 
// After splicing, the list contains: Sally Tom
// Deleted items are: Harry Dick

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1

Namespace

WinJS.Binding

Library

Base.js

See also

List

 

 

Show:
© 2014 Microsoft