# Looping Strategies?

**URL:** <https://community.postman.com/t/looping-strategies/35761>\
**Category:** Help Hub\
**Tags:** postman-sandbox\
**Created:** [May 30, 2022, 1:05am UTC](https://community.postman.com/t/looping-strategies/35761 "2022-05-30T01:05:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtfmoz2](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/rtfmoz2/32/6465_2.png) [@rtfmoz2](https://community.postman.com/u/rtfmoz2)\
**Post date:** [May 30, 2022, 1:05am UTC](https://community.postman.com/t/looping-strategies/35761/1 "2022-05-30T01:05:03Z")

</div>

I seriously struggled with looping through the various data sets being new to the language. In the end I ended up the with following code using lodash to reset all my environment vars at the start of each run.

```auto
name = ["resumeURL", "loginURL", "auth_code", "access_token", "refresh_token", "opentoken","refresh"]
_.forEach(name, (value) => { 
    pm.environment.unset(String(value),"")
});

```

There does appear to be an “.each” java construct but I don’t know how to use it. I would appreciate guidance from the crowd for some looping constructs like above for json, string, key/value pair and array indexes. I should not have to use lodash for this.

BONUS Points: If you have any tips on how to pull the initial value of an environment variable that would be amazing.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [May 30, 2022, 8:34am UTC](https://community.postman.com/t/looping-strategies/35761/2 "2022-05-30T08:34:15Z")

</div>

Hi @rtfmoz2

This may help you…

> [@Scripting the reset of collection variable to its initial value](https://community.postman.com/t/scripting-the-reset-of-collection-variable-to-its-initial-value/20620/3):
>
> if you still want to reset then use : Add this to first request’s pre-request script: pm.environment.set("resetValue",pm.collectionVariables.toJSON().values) This wiil store all initial value to resetValue variable And in the last request’s test script use pm.environment.get("resetValue").forEach((a)=\>pm.collectionVariables.set(a.key,a.value)) Now we are resetting all collectionVariables to the initially saved value
