Created
January 3, 2018 03:09
-
-
Save Neo-J/5be28caa5d9c54a2e45304b96de7e276 to your computer and use it in GitHub Desktop.
swap index of 2 items in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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