Created
October 10, 2018 06:17
-
-
Save ljayz/ab17e59eff93b3265cbcde0d74b18e5e to your computer and use it in GitHub Desktop.
Javascript Array to Object
This file contains 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
//from [{key1:val1},{key2:val2},{key3:val3}] to {key1:val1,key2:val2,key3:val3} | |
const array = [{key1:'val1'},{key2:'val2'},{key3:'val3'}]; | |
const arrayToObject = (accumulator, currentValue) => Object.assign(accumulator, currentValue); | |
array.reduce(arrayToObject, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment