0

I would be passing list of countries as environment variables as shown below

tag = 'us,gb,au,de'

I would like to dynamically construct key value array as shown below.

var placeList =
           [{place: 'us'},
            {place: 'gb'},
            {place: 'au'},
            {place: 'de'}];

I tried using .forEach, but was not sure how to construct one, any leads would be helpful.

1 Answer 1

1

You want to split the string on the comma then convert each string you receive in to an object

var placeList = tag.split(',').map(str => ({place: str}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.