Last active
February 13, 2019 09:18
-
-
Save hhyyg/55d4909b0f1092125029ca51855fa2f7 to your computer and use it in GitHub Desktop.
Object.assign(), Spread_syntax, Index Signatures
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
interface Foo { | |
readonly bar: number; | |
readonly baz: number; | |
} | |
const fooArray: Foo[] = [ | |
{ bar: 100, baz: 200 }, | |
{ bar: 300, baz: 400 }, | |
] | |
console.log(fooArray); | |
/* | |
Array(2) | |
0: {bar: 100, baz: 200} | |
1: {bar: 300, baz: 400} | |
*/ | |
const fooArray2 = fooArray.map(foo => { | |
const obj: any = {}; | |
obj[foo.bar] = foo.baz; | |
return obj | |
}); | |
console.log(Object.assign({}, ...fooArray2 )); | |
/* | |
Object | |
100: 200 | |
300: 400 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
basではなくbazなような( ´・?・`)