# How can I create variable that can have many string values?

**URL:** <https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270>\
**Category:** Help Hub\
**Tags:** variables, json, tests, collections, newman-project\
**Created:** [August 24, 2020, 3:49pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270 "2020-08-24T15:49:14Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anna.tirshenko](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@anna.tirshenko](https://community.postman.com/u/anna.tirshenko)\
**Post date:** [August 24, 2020, 3:49pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/1 "2020-08-24T15:49:14Z")

</div>

Hi everyone!

I need to create a variable, and manually set its different values, then I need that every time when sending the request it randomly chooses any of these values and put it in the request query.  
So, this is the request, It searches photos

GET `{{url}}/photos/tags/stars`

In the query, “stars” is a keyword, instead of “stars” I want to create a variable that will include many other keywords. For example “sun”, “earth” “flower”, “person” etc.  
And everytime when sending the request I need to pick one of these values randomly and use it in the request.

Thanks for the help

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [August 24, 2020, 8:28pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/2 "2020-08-24T20:28:12Z")

</div>

just like {{url}} create an array with list of all in items like “sun”, “earth” etc. {{items}} call that item with each request after once by one

```auto
var picof = ["Sun", "Earth", "flower", "person"];
pm.environment.set("pictocollect", picof );
var mypics= environment.pictocollect;
var getpics= mypics.pop();

```

work in test like

```auto
tests[getpics] = true;
pm.environment.set("pictocollect", mypics);

```

just an overview of it, havn’t tested it. a work around like this. hope it helps

you can refer this link as well.

> **[Single request loop](https://documenter.getpostman.com/view/5293839/SWLk35Jp?version=latest#622ca5f1-e899-425c-9c61-264934665133)**
>
> This Collection gets a list of IDs, then loops a POST request until all IDs have been sent.
> 
> The layout is as follows:
> 
> 
> \*\*GET ID list:\*\* https://postman-echo.com/get
> 
> Description:
> \- Response contains an array of numbers to use as dummy data.
> 
> Test...

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 25, 2020, 11:41am UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/3 "2020-08-25T11:41:38Z")

</div>

@gpub1’s solution works, but I’m going to offer something slightly different since you said “random every time”

You want to set your pictureKeywords to an array variable. I almost always use collection variables for this, since it relates to the collection, rather than the environment. You can either add this manually to the collection variables, or you can set it in a pre-request script.

```auto
const keywords = ['sun', 'earth', 'flower', 'person', 'star'];

```

To get a random one from the array without modifying it, you can use this pre-request script:

```auto
const keywords = ['sun', 'earth', 'flower', 'person', 'star'];
const index = Math.trunc(Math.random() * keywords.length);
const randomKeyword = keywords[index];
pm.collectionVariables.set('keyword', keyword);

```

In the url for your test, you can now access that variable the same way you had your base url  
GET `{{url}}/photos/tags/{{keyword}}`

---

<div class="post-metadata">

**Author:** ![anna.tirshenko](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@anna.tirshenko](https://community.postman.com/u/anna.tirshenko)\
**Post date:** [August 25, 2020, 12:37pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/4 "2020-08-25T12:37:37Z")

</div>

> [@allenheltondev](#):
>
> ```auto
> const keywords = ['sun', 'earth', 'flower', 'person', 'star'];
> const index = Math.trunc(Math.random() * keywords.length);
> const randomKeyword = keywords[index];
> pm.collectionVariables.set('keyword', keyword);
> 
> ```

Tanks for the response,  
I did the same as you mentioned, but I’m getting this error: `ReferenceError: keyword is not defined`

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 25, 2020, 12:40pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/5 "2020-08-25T12:40:01Z")

</div>

`randomKeyword` is probably what you need in that `set` function

```auto
pm.collectionVariables.set('keyword', randomKeyword);

```

---

<div class="post-metadata">

**Author:** ![anna.tirshenko](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@anna.tirshenko](https://community.postman.com/u/anna.tirshenko)\
**Post date:** [August 25, 2020, 12:41pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/6 "2020-08-25T12:41:00Z")

</div>

> [@allenheltondev](#):
>
> {{url}}/photos/tags/{{keyword}}

 ![Screen Shot 2020-08-25 at 16.39.29](https://us1.discourse-cdn.com/getpostman/original/3X/c/b/cb82a67cdc8b6c5584aeea4ee155de8aedb0b53c.png)

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 25, 2020, 12:51pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/7 "2020-08-25T12:51:47Z")

</div>

Thanks @danny-dainton, yes.

on line 4 change `randomKeyword` to just `keyword` and you’ll be good to go.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 25, 2020, 1:07pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/8 "2020-08-25T13:07:33Z")

</div>

Could have probably done this:

```auto
const keywords = ['sun', 'earth', 'flower', 'person', 'star'];
pm.collectionVariables.set('keyword', _.shuffle(keywords)[0])

```

Either way would get you to the same answer though 😃

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [August 25, 2020, 1:56pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/9 "2020-08-25T13:56:44Z")

</div>

I really need to use lodash more. It has everything.

---

<div class="post-metadata">

**Author:** ![gpub1](https://avatars.discourse-cdn.com/v4/letter/g/f6c823/32.png) [@gpub1](https://community.postman.com/u/gpub1)\
**Post date:** [August 25, 2020, 2:16pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/10 "2020-08-25T14:16:33Z")

</div>

agree on answer but some added value with new addition to test script with \_.shuffle 🙂

---

<div class="post-metadata">

**Author:** ![anna.tirshenko](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@anna.tirshenko](https://community.postman.com/u/anna.tirshenko)\
**Post date:** [August 25, 2020, 4:50pm UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/11 "2020-08-25T16:50:04Z")

</div>

@allenheltondev, @danny-dainton@gpub1 Thanks a lot 👍

---

<div class="post-metadata">

**Author:** ![srikanthpettem1](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/srikanthpettem1/32/33579_2.png) [@srikanthpettem1](https://community.postman.com/u/srikanthpettem1)\
**Post date:** [January 30, 2026, 9:25am UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/12 "2026-01-30T09:25:26Z")

</div>

I want to select the value from the list manually, for that what is the configuration?

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [January 30, 2026, 10:08am UTC](https://community.postman.com/t/how-can-i-create-variable-that-can-have-many-string-values/15270/13 "2026-01-30T10:08:39Z")

</div>

Hey @srikanthpettem1 👋

Welcome to the Postman Community! :postman:

That’s not possible in UI, variables are _strings_ and a referenced by a single value using the `{{...}}` syntax.

You can use an _array_ or an _object_ as the variable string value and then select one of those values, via a script, but there is no _manual selection_ aspect.

* * *

The only method I can think of to select something new each time would be to use a placeholder variable and then manually change the value inline or in the _All Variables_ section before the request is sent.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/2/92a167443f6d75b4e3b4fe656c669dae0c9f5b08.png)
