I have the following TypeScript enum:
JavaScript
x
5
1
export declare enum SupportedLanguages {
2
en,
3
fr
4
}
5
If I import it in my react application and console.log
it, I will get the following object returned:
JavaScript
1
5
1
{
2
en: "en",
3
fr: "fr"
4
}
5
How can I manipulate it, so that I get the following object returned?
JavaScript
1
5
1
{
2
en: "",
3
fr: ""
4
}
5
I tried it with const Lang = Object.keys(SupportedLanguages)
and also with .map()
but I did not get the expected object returned.
Advertisement
Answer
Are you just looking to get a new object with all the data as empty strings?
JavaScript
1
12
12
1
var supportedLanguages = {
2
en: "en",
3
fr: "fr"
4
};
5
6
var result = Object.keys(supportedLanguages)
7
.reduce((accum, key) =>
8
Object.assign(accum, { [key]: "" })
9
, {});
10
11
console.log(result); // { "en": "", "fr": "" }
12