Examples
const values = ['a', 'b', 'c']
swapRemove(values, 0)
// values is ['c', 'b']Function
swapRemove<T>(arr: T[], index: number): voidRemoves an item by replacing it with the array’s final item, then popping the final item. Use this when the array’s order does not matter.
An index of -1 is treated as a no-op. Other indexes are not validated. If
the removed item is not the final item and the final item is falsy, the final
item is still popped but the target slot is left unchanged because the
implementation uses a truthiness check.
const values = ['a', 'b', 'c']
swapRemove(values, 0)
// values is ['c', 'b']