# There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'shift' of undefined

**URL:** <https://community.postman.com/t/there-was-an-error-in-evaluating-the-pre-request-script-typeerror-cannot-read-property-shift-of-undefined/18094>\
**Category:** Help Hub\
**Tags:** tests, variables, collections\
**Created:** [November 29, 2020, 9:21pm UTC](https://community.postman.com/t/there-was-an-error-in-evaluating-the-pre-request-script-typeerror-cannot-read-property-shift-of-undefined/18094 "2020-11-29T21:21:44Z")\
**Posts on this page:** 1\
**Showing post:** 13

<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:** [December 1, 2020, 9:53pm UTC](https://community.postman.com/t/there-was-an-error-in-evaluating-the-pre-request-script-typeerror-cannot-read-property-shift-of-undefined/18094/13 "2020-12-01T21:53:05Z")

</div>

Ok your last message was telling of what was wrong.

Your prerequest script in fact is resetting the array every time.

**Pre-request script:**

```auto
var buyerProgramId= [‘1961’, ‘1962’, ‘1972’, ‘1976’, ‘1977’];
pm.globals.set(“buyerProgramId”, JSON.stringify(buyerProgramId));

```

This is where you want to do your array manipulation. You should be popping the array and saving the new contents here.

```auto
let buyerProgramId = pm.globals.get('buyerProgramId');
if(!buyerProgramId){
  buyerProgramId= ['1961', '1962', '1972', '1976', '1977'];
}
else {
  buyerProgramId = JSON.parse(buyerProgramId);
}

let currentId = buyerProgramId.pop();
pm.globals.set('currentId', currentId);
pm.globals.set('buyerProgramId', JSON.stringify(buyerProgramId));

```

Then in your tests, you just need to evaluate if there are more items in the array

**Tests:**

```auto
let buyerProgramId = JSON.parse(pm.globals.get('buyerProgramId'));
if(buyerProgramId.length) {
  postman.setNextRequest(request.name);
} else {
  postman.setNextRequest(null);
}

```

---

_[View the full topic](https://community.postman.com/t/there-was-an-error-in-evaluating-the-pre-request-script-typeerror-cannot-read-property-shift-of-undefined/18094)._
