Skip to content

Instantly share code, notes, and snippets.

@Neo-J
Created January 3, 2018 03:09
Show Gist options
  • Save Neo-J/5be28caa5d9c54a2e45304b96de7e276 to your computer and use it in GitHub Desktop.
Save Neo-J/5be28caa5d9c54a2e45304b96de7e276 to your computer and use it in GitHub Desktop.
swap index of 2 items in an array
function swapItem(arr, fromIndex, toIndex) {
arr[toIndex] = arr.splice(fromIndex, 1, arr[toIndex])[0];
return arr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment