Skip to content

Instantly share code, notes, and snippets.

@ljayz
Created October 10, 2018 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljayz/ab17e59eff93b3265cbcde0d74b18e5e to your computer and use it in GitHub Desktop.
Save ljayz/ab17e59eff93b3265cbcde0d74b18e5e to your computer and use it in GitHub Desktop.
Javascript Array to Object
//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