Skip to content

Instantly share code, notes, and snippets.

@yancya
Last active December 26, 2020 15:42
Show Gist options
  • Save yancya/4276d5054a000375f1a973c719930d7d to your computer and use it in GitHub Desktop.
Save yancya/4276d5054a000375f1a973c719930d7d to your computer and use it in GitHub Desktop.
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