How to check if a variable is odd or even?

Hi I have a basic script that I am using with a .csv to populate some variables in the body, this is working fine.

I now have a need to check if one of the variables in the .csv {{NODE-ID}} is odd or even and then depending on the result populate an environmental variable called {{GROUP}} with the text “GROUP-ODD” or “GROUP-EVEN”.

It seems simple but I am not sure where to start. I have been reading about the javascrip isOdd and isEven functions but I dont know how to incorporate them into a postman pre-check hope someone can help with this!


Hey @chollobill. First of all, welcome to the community. :smile:

Coming to your question, you could use data variables within Postman to achieve this. Refer to this document to know more about them.

To summarise, you would have a data variable available to you within the test scripts. The data variable would refer to each individual row in your csv file. You can add a dummy request(to let’s say whose test script you use for this manipulation, which runs before the actual request.

Let’s say your csv file has two columns. The node id and the number you want to check, in this case data would be:

  "nodeId": 1,
  "number": 4

Once you have the data object in place, you could then do your check. It would look something like:

function isEven (number) {
    return number%2 === 0;

if (data.node === REQUIRED_NODE_ID) {
    if (isEven(data.number)) {
        pm.environment.set('GROUP_EVEN', DESIRED_VALUE)
    else {
        pm.environment.set('GROUP_ODD', DESIRED_VALUE)

Hope this helps. Feel free to reach out in case you have additional querries.