Last active
February 1, 2019 14:30
-
-
Save zplume/a8374f90ea9398bbd88c08adc37e6401 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
// create an object from an array of values with Array.reduce | |
const objectFromArray = [4,5,6].reduce((output, item, index) => { | |
output[index] = item; // assign new key/value to output object | |
return output; | |
}, | |
{} // initial value - empty object | |
); | |
// objectFromArray: | |
// {0: 4, 1: 5, 2: 6} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment