List
A list of items that can be read and updated.
Type Parameters
• S
• M
Methods
countfunctionGets the number of items in the list.
Returns
The number of items.
number
toArrayfunctionConverts the list to an array.
Returns
An array containing all items. The items are the same as in the list.
readonly M[]
forEachfunctionExecutes a function for each item in the list.
Parameters
callbackForEachCallback<M>The function to run for each item.
Parameters
itemMThe current item in the list.
Returns
void
Returns
void
filterfunctionCreates a new array with items that pass a test.
Parameters
filterFilterPredicate<M>A function that tests each item. Returns true to keep the item.
Parameters
itemMThe item to test.
Returns
true if the item should be included, otherwise false.
boolean
Returns
An array of items that passed the test.
readonly M[]
insertBeforefunctionAdds a copy of an item to the list and places it right before another item.
Parameters
refM | undefinedThe existing item to place the new item before.
If ref is undefined, the new item is added at the end of the list.
If ref does not exist in the list, the operation fails.
itemSThe item to add. A copy of this item will be inserted.
Returns
The added item, or undefined if the operation failed.
M | undefined
insertAfterfunctionAdds a copy of an item to the list and places it right after another item.
Parameters
refM | undefinedThe existing item to place the new item after.
If ref is undefined, the new item is added at the end of the list.
If ref does not exist in the list, the operation fails.
itemSThe item to add. A copy of this item will be inserted.
Returns
The added item, or undefined if the operation failed.
M | undefined
moveBeforefunctionMoves an existing item to a new position right before another item.
Parameters
refM | undefinedThe existing item to move the item before.
If ref is undefined, the item is moved to the end of the list.
If ref does not exist in the list, the operation fails.
itemMThe item to move. The operation fails if the item is not already in the list.
Returns
void
moveAfterfunctionMoves an existing item to a new position right after another item.
Parameters
refM | undefinedThe existing item to move the item after.
If ref is undefined, the item is moved to the end of the list.
If ref does not exist in the list, the operation fails.
itemMThe item to move. The operation fails if the item is not already in the list.
Returns
void
deletefunctionRemoves an item from the list.
Parameters
itemMThe item to remove from the list.
Returns
void