Last active
June 15, 2019 16:21
-
-
Save snapwich/e20ed4df05a83790dc3135ebead0d193 to your computer and use it in GitHub Desktop.
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
let items = [ | |
{name: "something", value: true}, | |
// ... | |
]; | |
// use reduce to build the new map into an accumulator | |
// we'll refer to this as "reduce mutate" | |
let result = items.reduce((acc, item) => { | |
acc[item.name] = item.value; | |
return acc; | |
}, {}) | |
// equivalent as as a for loop | |
let result = {}; | |
for(let item of items) { | |
result[item.name] = item.value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment