Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. let items = [
  2. {name: "something", value: true},
  3. // ...
  4. ];
  5.  
  6. // use reduce to build the new map into an accumulator
  7. // we'll refer to this as "reduce mutate"
  8. let result = items.reduce((acc, item) => {
  9. acc[item.name] = item.value;
  10. return acc;
  11. }, {})
  12.  
  13. // equivalent as as a for loop
  14. let result = {};
  15. for(let item of items) {
  16. result[item.name] = item.value;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement