0

I know this is a basic question, but I am trying to create a data structure that is baffling me at the moment.

I have a string array like so:

let stringArray = ['Core', 'Regional'];

And I would like to create this data structure:

[
  {'key': 'Core', 'text': 'Core'},
  {'key': 'Regional', 'text': 'Regional'}
]

How can I .map over the stringArray to create the data structure above?

0

1 Answer 1

1

You can try this solution

let stringArray = ['Core', 'Regional'];

stringArray = stringArray.map(str => ({key: str, text: str}));

console.log(stringArray);

Sign up to request clarification or add additional context in comments.

1 Comment

In 10 minutes I can ser :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.