Skip to content

array

Array utilities.

FunctionDescription
filterInPlaceFilter an array in place.
snapshotCopies an iterable into a new array, so it can be safely iterated while the original is modified. Use this whenever the loop body (or an awaited call inside it) adds to or removes from the collection being iterated — releasing locks, cancelling timers, settling pending operations. Iterating the live collection in those cases silently skips entries. Prefer this over an inline [...collection]: it says why the copy exists, and it keeps the call site clear of unicorn/no-useless-spread, which cannot tell a defensive copy from a redundant one. The result is readonly: it exists to be iterated, not worked on. Mutating it would change a throwaway copy and leave the original untouched, which is never what the caller wants.
uniqueRemove duplicates from an array.
uniqueInPlaceRemove duplicates from an array in place.