Skip to content

Instantly share code, notes, and snippets.

@ehsaneona
Created November 13, 2022 08:39
Show Gist options
  • Select an option

  • Save ehsaneona/db25854b1f9922752c8cb9b891b0b79c to your computer and use it in GitHub Desktop.

Select an option

Save ehsaneona/db25854b1f9922752c8cb9b891b0b79c to your computer and use it in GitHub Desktop.
Moving an Index from the Array and moving to the specified Index
export const swapArrayIndex = (array, currentIndex, moveIndex) => {
if (!array[moveIndex] || !array[currentIndex]) return array;
let changedArray = [...array];
changedArray[currentIndex] = array[moveIndex];
changedArray[moveIndex] = array[currentIndex];
return changedArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment