Created
March 27, 2017 16:56
-
-
Save Magellol/7262cf9b45f62eda28cf1c7e647bc6ab to your computer and use it in GitHub Desktop.
Removing an index from an array.
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
/** | |
* Remove an index from an array. | |
* This creates a new array without the index we're removing. | |
* Because of that, indexes are re-created so there isn't any empty spot. | |
* | |
*/ | |
export function removeIndexFrom(array, indexToRemove) { | |
return [ | |
...array.slice(0, indexToRemove), | |
...array.slice(indexToRemove + 1), | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment