array-clear
v1.0.0
Published
Clear an array by setting its length to 0.
Maintainers
Readme
array-clear
Set an array's length to 0.
import arrayClear from "array-clear";
const items = [1, 2, 3];
arrayClear(items);
// items => []Mutates the array in place and returns the same reference. Throws a TypeError if the argument is not an array.
Install
npm install array-clearAPI
arrayClear<T>(array: T[]): T[]
Clears array by assigning array.length = 0.
| Input | Behavior |
| ------------------- | ----------------------------------------- |
| Mutable array | Cleared in place; same reference returned |
| Already empty array | No-op; same reference returned |
| Non-array | Throws TypeError |
| Frozen array | Throws TypeError (engine behavior) |
License
MIT
