# Perform actions on the basis of iteration count in Collection Runner

**URL:** <https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739>\
**Category:** Help Hub\
**Tags:** csvdatafile\
**Created:** [September 20, 2018, 3:13pm UTC](https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739 "2018-09-20T15:13:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gherghinoiu](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gherghinoiu](https://community.postman.com/u/gherghinoiu)\
**Post date:** [September 20, 2018, 3:13pm UTC](https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739/1 "2018-09-20T15:13:34Z")

</div>

I am doing some speed testing and I have the following issue:

- I am running the collection and uploading the CSV file
- I want to list an array that grabbed some data from all the calls but only after the last call

I managed to do it when I know the number of the rows in the CSV file but how can I achieve this when I don’t know the number of rows.

So in my case, I am grabbing the times into an array like this:

response\_array = globals[‘response\_times’] ? JSON.parse(globals[‘response\_times’]) : []  
response\_array.push(responseTime);  
postman.setGlobalVariable(“response\_times”, JSON.stringify(response\_array));

And in the end, I have this piece of code that lists the array in the console after all the rows finished:

if (response\_array.length === 25) {  
console.log("response\_times are: " +pm.globals.get(“response\_times”));  
}

This works because I know that there are 25 rows in my CSV, but how can I achieve the same thing without knowing how many rows the CSV has.

Thank you for taking the time to read this or respond!

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [September 20, 2018, 3:35pm UTC](https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739/2 "2018-09-20T15:35:52Z")

</div>

Hey @gherghinoiu, the good news is that it’s solvable!

So, if you scroll down the docs - [https://www.getpostman.com/docs/v6/postman/scripts/postman\_sandbox\_api\_reference](https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference)

You’ll see that in the `pm.info` object, there’s a property called as `iterationCount` which is the total number of iterations that are scheduled to run.

Now,  
Total number of iterations === Number of rows in your CSV File

Also, instead of using the `response_array.length` you can use another property of the `pm.info` object viz. `pm.info.iteration` which gives you the current iteration number.

So, to sum it up:

In your test-script you can put the following code snippet:

```javascript
// Since, pm.info.iteration starts from 0
// Thus, we'll check if iteration === iterationCount - 1
if (pm.info.iteration === pm.info.iterationCount - 1) {
    console.log(`response_times are: ${pm.globals.get('response_times')}`);
}

```

---

<div class="post-metadata">

**Author:** ![gherghinoiu](https://avatars.discourse-cdn.com/v4/letter/g/ac91a4/32.png) [@gherghinoiu](https://community.postman.com/u/gherghinoiu)\
**Post date:** [September 20, 2018, 3:56pm UTC](https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739/3 "2018-09-20T15:56:11Z")

</div>

@singhsivcan Thank you for the fast reply. This is exactly what I needed! Best wishes!

---

<div class="post-metadata">

**Author:** ![singhsivcan](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/singhsivcan/32/1595_2.png) [@singhsivcan](https://community.postman.com/u/singhsivcan)\
**Post date:** [September 20, 2018, 3:57pm UTC](https://community.postman.com/t/perform-actions-on-the-basis-of-iteration-count-in-collection-runner/2739/4 "2018-09-20T15:57:33Z")

</div>

Most welcome!  
Feel free to reach out in case you need any further help!
