Skip to main content

arrayMove

Re-orders an array given 2 indexes:

  • The old position;
  • and the new position.

API

function arrayMove<Source>(array: Source[], fromIndex: number, toIndex: number): Source[];

Usage

import { arrayMove } from "@feedzai/js-utilities";

const DATA = [
"Homer",
"Marge",
"Lisa",
"Bart",
"Maggie"
];

const SORTED = arrayMove(DATA, 2, 0);

console.log(SORTED) // ["Lisa", "Homer", "Marge", "Bart", "Maggie"];