Created
May 19, 2020 11:16
-
-
Save claudiohilario/e71b9164a2992d6cb4d5f6d3b71277ba to your computer and use it in GitHub Desktop.
Move Array Index
This file contains hidden or 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
const moveArrayIndex = (arr, fromIndex, toIndex) => { | |
const elementFrom = arr[fromIndex]; | |
arr.splice(fromIndex, 1); | |
arr.splice(toIndex, 0, elementFrom); | |
return [...arr]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment