Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement