Created
May 26, 2017 10:45
-
-
Save srph/943081f31559c4cfe9bdb2f28d536acd to your computer and use it in GitHub Desktop.
JS: Array to object
This file contains hidden or 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
| /** | |
| * Converts array to object with sparse values. | |
| * Useful when for example, using a dictionary to set mass ids to a value | |
| * { loading: { 1: true, 4: true } } | |
| * | |
| * @param {array} array Primitive values | |
| * @return {object} | |
| */ | |
| export default function objectify(array, value) { | |
| const result = {}; | |
| array.forEach(key => { | |
| result[key] = value; | |
| }) | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment