splice
Insert and remove elements from a DefineList.
list.splice(index[, howMany[, ...newItems]])
Removes howMany
items at index
and adds newItems
in their place.
Parameters
- index
{Number}
:Where to start removing or inserting elements.
- howMany
{Number}
:The number of elements to remove If howMany is not provided,
splice
will remove all elements fromindex
to the end of the DefineList. - newItems
{*}
:Items to insert into the DefineList
Returns
{Array}
:
The elements removed by splice
.
Use
splice
lets you remove elements from and insert elements into a DefineList.
This example demonstrates how to do surgery on a list of numbers:
var list = new DefineList([0, 1, 2, 3]);
// starting at index 2, remove one element and insert 'Alice' and 'Bob':
list.splice(2, 1, 'Alice', 'Bob');
list.get(); // [0, 1, 'Alice', 'Bob', 3]
Events
splice
causes the DefineList it's called on to emit
add events, remove events, and length events. If there are
any elements to remove, a remove event, and a
length event will be fired. If there are any elements to insert, a
separate add event, and a separate length event
will be fired.