Inserts an item at the given index into the array. Existing items at and after the index will be pushed back. No items will be deleted. Original array is mutated.
const arr = [1, 2, 3];
arr.insert(1, 5); // arr is now [1, 5, 2, 3]
The index of which to insert the item.
The item to insert.
Inserts an item at the given index into the array. Existing items at and after the index will be pushed back. No items will be deleted. Original array is mutated. *
const arr = [1, 2, 3];
arr.insertRange(1, [5, 6]); // arr is now [1, 5, 6, 2, 3]
The index of which to start the insertion.
The items to insert.
Removes an item from the array. Original array is mutated.
const numbers = [1, 2, 3];
const res = numbers.remove(2); // numbers is modified in place. res is true because element was in the array.
true if item was found and removed from array. False if item was not found in the array.
Item to remove from array.
Removes all items from the array that pass the predicate. Original array is mutated.
const arr = [1, 2, 3, 4];
arr.removeAll(x => x > 2); // arr is now [1, 2]
The number of removed items.
The predicate to test for a condition.
Generated using TypeDoc
Removes all items from the array. Original array is mutated.
Example