List.splice method
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: NumberThe zero-based location in the list from which to start removing elements.
howMany
Type: NumberThe number of elements to remove.
item
Type: ObjectThe 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", "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] + " ";
</script>
// Output:
// After splicing, the list contains: Sally Tom
// Deleted items are: Bill Sam
Requirements
Minimum WinJS version |
WinJS 1.0 |
Namespace |
WinJS.Binding |