Created
December 10, 2017 22:21
-
-
Save gp22/08172c7002f17f8d3be8b175d4f76bc8 to your computer and use it in GitHub Desktop.
Array snippets in JS
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
// Use slice and reduce to create a new array with new elements inserted | |
[array[0], ...array.slice(1).reduce((arr, existingElement) => [...arr, elementToInsert, existingElement], [])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment