# Set env variables in multiple loops

**URL:** <https://community.postman.com/t/set-env-variables-in-multiple-loops/15986>\
**Category:** Help Hub\
**Tags:** variables, environments, collections\
**Created:** [September 18, 2020, 3:51am UTC](https://community.postman.com/t/set-env-variables-in-multiple-loops/15986 "2020-09-18T03:51:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyawswar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kyawswar/32/5615_2.png) [@kyawswar](https://community.postman.com/u/kyawswar)\
**Post date:** [September 18, 2020, 3:51am UTC](https://community.postman.com/t/set-env-variables-in-multiple-loops/15986/1 "2020-09-18T03:51:15Z")

</div>

I want to test the following workflow structure and set env in each request.

**In first request test script,**

```
var st = [1,2,3]

var i = st.length;

for(var j=0; j<i; j++) {

    pm.environment.set("id", st[j]);

    postman.setNextRequest("nextRequest");

};

```

**in Next Request prescript,**

`console.log(`Run ${pm.environment.get(“id”)}`);`

in console log, there is only **Run 3** shown.

The problem is that the env variables are overwritten with the last elements. And I can see only the last element of the list and the request is using the last element.

I would like to know How can I keep the env variables not to be overwritten?

---

<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:** [September 18, 2020, 11:50am UTC](https://community.postman.com/t/set-env-variables-in-multiple-loops/15986/2 "2020-09-18T11:50:47Z")

</div>

I actually just answered this for somebody yesterday.

[Take a look](https://community.postman.com/t/capture-json-guid-value-and-save-in-different-variable-for-each-iteration/15902/14)
