Last active
January 12, 2022 07:07
-
-
Save ancyrweb/56f4e0ffc09a33128afb6ffae4e1c964 to your computer and use it in GitHub Desktop.
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 elements = [1, 2, 4, 5]; | |
const indexToInsert = 2; // we will append the element at index 2 | |
const elementToInsert = 3; // we will insert the number "3" | |
const nextElements = [ | |
...elements.slice(0, indexToInsert), | |
elementToInsert, | |
...elements.slice(indexToInsert), | |
]; // [1, 2, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment