Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript: Use strings from a list of strings

I have a use case of performing an API call, which accepts parameters like this:

api('str1', 'str2', 'str3');

I don’t want to hardcode all parameters so I’m trying to do something like this:

const LIST: string[] = ['list-item-1', 'list-item-2'];

api('str1-hardcoded', LIST.join(','))

But this does not solve the issue, as join produces a single string from all items which is not what I want.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What would be the best way to handle this?

>Solution :

You just need use ...

const LIST: string[] = ['list-item-1', 'list-item-2'];

api('str1-hardcoded', ...LIST)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading