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
|
Namespace |
WinJS.Binding |
|---|---|
|
Library |
|
See also
Build date: 12/5/2012