R
fn

move

v0.0.10tested

Return a new array with the item at `from` moved to `to`. Out-of-range `from` returns a shallow copy unchanged; `to` is clamped into range. Never mutates.

Example

ts
move(['a', 'b', 'c'], 0, 2); // ['b', 'c', 'a']

Signature

ts
export function move<T>(array: readonly T[], from: number, to: number): T[]{ ... }

Type Parameters

T

Parameters

ParameterTypeDescription
arrayreadonly T[]The source array
fromnumberIndex to move from
tonumberIndex to move from

Returns

T[]A new array with the item moved