# How to reset my environment variable after certain number of iterations run

**URL:** <https://community.postman.com/t/how-to-reset-my-environment-variable-after-certain-number-of-iterations-run/16538>\
**Category:** Help Hub\
**Created:** [October 7, 2020, 9:30am UTC](https://community.postman.com/t/how-to-reset-my-environment-variable-after-certain-number-of-iterations-run/16538 "2020-10-07T09:30:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [October 7, 2020, 9:30am UTC](https://community.postman.com/t/how-to-reset-my-environment-variable-after-certain-number-of-iterations-run/16538/1 "2020-10-07T09:30:26Z")

</div>

I have a collection which has 2 request, request A will pull a set of records and store in an arraylist as variable. request B will iterate on this records one after another based on the iteration number defined during collection run. Now I want to reset the iteration count after certain number of iterations how can I do this? Can anyone help

I tried below snippet in prescript of A request but it didn’t work:  
function cleanup() {

```
const clean = _.keys(pm.environment.toObject())

_.each(clean, (itemOfArray) => {

    if (itemOfArray.eql(10)) {

        pm.environment.unset(itemOfArray)

    }

})

```

}

---

<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:** [October 7, 2020, 11:23am UTC](https://community.postman.com/t/how-to-reset-my-environment-variable-after-certain-number-of-iterations-run/16538/2 "2020-10-07T11:23:05Z")

</div>

Is the number of iterations static? Meaning do you always want to reset it after 10 iterations? Or do the number of iterations vary?

The command to unset an environment variable in postman is:

```auto
pm.environment.unset('myVariableName');

```

So if you know your terminating condition, you can always just call that command once it triggers.

---

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [October 7, 2020, 11:42am UTC](https://community.postman.com/t/how-to-reset-my-environment-variable-after-certain-number-of-iterations-run/16538/3 "2020-10-07T11:42:52Z")

</div>

Thanks allen for your reply, i tried another way and it worked. added the below snippet in request A pre-request script:

//resetting back to 0 the counter

let count\_uci = pm.environment.get(“itemOfArray”);

let count\_entity = pm.environment.get(“entityOfArray”);

console.log(count\_uci);

console.log(count\_entity);

```
if ((count_uci == 10) && (count_entity == 10)) 

{

    pm.environment.set("itemOfArray","0");

    pm.environment.set("entityOfArray","0");

    console.log(count_uci);

    console.log(count_entity);

}
```
