0

Hi I would like to parse array with strings/enumerates into http params in Angular.

My example http request:

http://localhost:8091/air-quality?cities=cityname1,cityname2,cityname3

Example arrays (I didnt realize this yet but I will probably use the 2nd option):

cities = ["london", "madrid", "paris"] or cities = [LONDON, MADRID, PARIS]

request:

this.httpClient.get<number>(this.url, {params: params});

At this moment I can just build long string but it will look pretty bad. I tried use stringify but this method added %5D at the begin and end of params.

0

1 Answer 1

1

You can use array join():

let params = cities.join(',');
Sign up to request clarification or add additional context in comments.

1 Comment

ohhh, that was pretty easy and solve my question, thank u

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.