I have a string array & need to create key & value like below….
const output = { string1: true, string2: true, string3: true };
Example
const strarray = ["string1","string2","string3"];
I need output like
const output = { string1: true, string2: true, string3: true };
How to achieve in React-Typescript?
2
Answers
You can use
reduce
method to generate object from array of stringI understand the question is
how can I achieve in react-ts
. so I think it is easy. the above answer was correct but there are some linting errors. I want to suggest like:hope that can help your listing error. *** cause there are too many edits. I write it as a answer. #credit above answer
example