Last active
June 1, 2018 09:33
-
-
Save pocotan001/981d558660c147af3fa5391bc32212a5 to your computer and use it in GitHub Desktop.
Create an object instead of an array
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
const ABC = ["a", "b", "c"]; | |
ABC.reduce((acc, key) => { | |
acc[key] = `${key}!`; | |
return acc; | |
}, Object.create(null)); | |
ABC.reduce( | |
(acc, key) => Object.assign(acc, { [key]: `${key}!` }), | |
Object.create(null) | |
); | |
ABC.reduce( | |
(acc, key) => ({ | |
...acc, | |
[key]: `${key}!` | |
}), | |
Object.create(null) | |
); | |
// { a: "a!", b: "b!", c: "c!" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment