Array
Utils function for array manipulate
reorder
Reorder list items
reorder(array, startIndex, endIndex)
Arguments
array (T[]
): list of item want to reorder
startIndex (number
): start item index want to replace position
endIndex (number
): end item index want to replace position
Return
T[]
: array after reorder
Example
const data = [
{ label: 'item 1' },
{ label: 'item 2' },
{ label: 'item 3' },
{ label: 'item 4' },
]
reorder(data, 1, 3)
// => [
// { label: 'item 1' },
// { label: 'item 4' }, // replace with item 2
// { label: 'item 3' },
// { label: 'item 2' }, // replace with item 4
// ]