Skip to main content

Function: moveItem()

moveItem<T>(items, from, to): T[]

Defined in: src/lib/utils/array/index.ts:10

Return a copy of a list with one item moved from one index to another. Items in between shift to fill the gap.

Indexes are clamped to the list bounds.

Type Parameters​

T​

T

Parameters​

items​

readonly T[]

from​

number

to​

number

Returns​

T[]

Example​

moveItem(["a", "b", "c"], 0, 2); // ["b", "c", "a"]
moveItem(["a", "b", "c"], 2, 0); // ["c", "a", "b"]