Last active
December 26, 2020 15:42
-
-
Save yancya/4276d5054a000375f1a973c719930d7d to your computer and use it in GitHub Desktop.
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
type Key = ['a','b','c'] | |
type Value = [string, number, boolean] | |
type Obj = {a: string, b: number, c: boolean}; | |
const keys: Key = ['a','b','c']; | |
const values: Value = ['a', 1, true]; | |
const object: Obj = keys.reduce((acc, key, index) => { | |
acc[key] = values[index]; | |
return acc; | |
}, {}) as Obj; | |
console.log(object); //=> { a: 'a', b: 1, c: true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment